diff --git a/.changes/unreleased/Features-20240521-202252.yaml b/.changes/unreleased/Features-20240521-202252.yaml new file mode 100644 index 0000000000..49bfda8e39 --- /dev/null +++ b/.changes/unreleased/Features-20240521-202252.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Enable predicate pushdown for categorical dimensions +time: 2024-05-21T20:22:52.841802-07:00 +custom: + Author: tlento + Issue: "1011" diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml index e8f6a3100e..877453249f 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml +++ b/metricflow-semantics/metricflow_semantics/test_helpers/semantic_manifest_yamls/simple_manifest/metrics.yaml @@ -263,7 +263,8 @@ metric: name: instant_booking_fraction_of_max_value description: | Average instant booking value as a ratio of overall max booking value. - Tests constrained ratio measure. + Tests constrained ratio measure and predicate pushdown with different filters + on the same measure input. type: ratio type_params: numerator: @@ -331,7 +332,8 @@ metric: name: regional_starting_balance_ratios description: | First day account balance ratio of western vs eastern region starting balance ratios, - used to test interaction between semi-additive measures and measure constraints + used to test interaction between semi-additive measures and measure constraints, and + behavior of predicate pushdown when there are multiple filters on the same categorical dimension type: ratio type_params: numerator: diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index 4cf1afe3a5..84067fd722 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -184,7 +184,9 @@ def _build_query_output_node( ) ) - predicate_pushdown_state = PredicatePushdownState(time_range_constraint=query_spec.time_range_constraint) + predicate_pushdown_state = PredicatePushdownState( + time_range_constraint=query_spec.time_range_constraint, where_filter_specs=query_level_filter_specs + ) return self._build_metrics_output_node( metric_specs=tuple( @@ -251,6 +253,7 @@ def _build_aggregated_conversion_node( disabled_pushdown_state = PredicatePushdownState.with_pushdown_disabled() time_range_only_pushdown_state = PredicatePushdownState( time_range_constraint=predicate_pushdown_state.time_range_constraint, + where_filter_specs=tuple(), pushdown_enabled_types=frozenset([PredicateInputType.TIME_RANGE_CONSTRAINT]), ) @@ -511,6 +514,11 @@ def _build_base_metric_output_node( ), descendent_filter_specs=metric_spec.filter_specs, ) + if predicate_pushdown_state.where_filter_pushdown_enabled: + predicate_pushdown_state = PredicatePushdownState.with_additional_where_filter_specs( + original_pushdown_state=predicate_pushdown_state, + additional_where_filter_specs=metric_input_measure_spec.filter_specs, + ) logger.info( f"For\n{indent(mf_pformat(metric_spec))}" @@ -568,6 +576,9 @@ def _build_derived_metric_output_node( # If metric is offset, we'll apply where constraint after offset to avoid removing values # unexpectedly. Time constraint will be applied by INNER JOINing to time spine. + # We may consider encapsulating this in pushdown state later, but as of this moment pushdown + # is about post-join to pre-join for dimension access, and relies on the builder to collect + # predicates from query and metric specs and make them available at measure level. if not metric_spec.has_time_offset: filter_specs.extend(metric_spec.filter_specs) @@ -751,7 +762,9 @@ def _build_plan_for_distinct_values(self, query_spec: MetricFlowQuerySpec) -> Da required_linkable_specs, _ = self.__get_required_and_extraneous_linkable_specs( queried_linkable_specs=query_spec.linkable_specs, filter_specs=query_level_filter_specs ) - predicate_pushdown_state = PredicatePushdownState(time_range_constraint=query_spec.time_range_constraint) + predicate_pushdown_state = PredicatePushdownState( + time_range_constraint=query_spec.time_range_constraint, where_filter_specs=query_level_filter_specs + ) dataflow_recipe = self._find_dataflow_recipe( linkable_spec_set=required_linkable_specs, predicate_pushdown_state=predicate_pushdown_state ) @@ -954,7 +967,14 @@ def _find_dataflow_recipe( node_data_set_resolver=self._node_data_set_resolver, ) - if predicate_pushdown_state.has_pushdown_potential: + if predicate_pushdown_state.has_pushdown_potential and default_join_type is not SqlJoinType.FULL_OUTER: + # TODO: encapsulate join type and distinct values state and eventually move this to a DataflowPlanOptimizer + # This works today because all of our subsequent join configuration operations preserve the join type + # as-is, or else switch it to a CROSS JOIN or INNER JOIN type, both of which are safe for predicate + # pushdown. However, there is currently no way to enforce that invariant, so we will need to move + # to a model where we evaluate the join nodes themselves and decide on whether or not to push down + # the predicate. This will be much more straightforward once we finish encapsulating our existing + # time range constraint pushdown controls into this mechanism. candidate_nodes_for_left_side_of_join = list( node_processor.apply_matching_filter_predicates( source_nodes=candidate_nodes_for_left_side_of_join, diff --git a/metricflow/plan_conversion/node_processor.py b/metricflow/plan_conversion/node_processor.py index 9373cf0c66..0bf08942cf 100644 --- a/metricflow/plan_conversion/node_processor.py +++ b/metricflow/plan_conversion/node_processor.py @@ -3,15 +3,16 @@ import dataclasses import logging from enum import Enum -from typing import FrozenSet, List, Optional, Sequence, Set +from typing import Dict, FrozenSet, List, Optional, Sequence, Set from dbt_semantic_interfaces.enum_extension import assert_values_exhausted -from dbt_semantic_interfaces.references import EntityReference, TimeDimensionReference +from dbt_semantic_interfaces.references import EntityReference, SemanticModelReference, TimeDimensionReference from metricflow_semantics.filters.time_constraint import TimeRangeConstraint from metricflow_semantics.mf_logging.pretty_print import mf_pformat +from metricflow_semantics.model.semantics.linkable_element import LinkableElementType from metricflow_semantics.model.semantics.semantic_model_join_evaluator import MAX_JOIN_HOPS from metricflow_semantics.model.semantics.semantic_model_lookup import SemanticModelLookup -from metricflow_semantics.specs.spec_classes import LinkableInstanceSpec, LinklessEntitySpec +from metricflow_semantics.specs.spec_classes import LinkableInstanceSpec, LinklessEntitySpec, WhereFilterSpec from metricflow_semantics.specs.spec_set import group_specs_by_type from metricflow_semantics.specs.spec_set_transforms import ToElementNameSet from metricflow_semantics.sql.sql_join_type import SqlJoinType @@ -25,6 +26,7 @@ from metricflow.dataflow.nodes.filter_elements import FilterElementsNode from metricflow.dataflow.nodes.join_to_base import JoinDescription, JoinOnEntitiesNode from metricflow.dataflow.nodes.metric_time_transform import MetricTimeDimensionTransformNode +from metricflow.dataflow.nodes.where_filter import WhereConstraintNode from metricflow.validation.dataflow_join_validator import JoinDataflowOutputValidator logger = logging.getLogger(__name__) @@ -95,7 +97,10 @@ class PredicatePushdownState: """ time_range_constraint: Optional[TimeRangeConstraint] - pushdown_enabled_types: FrozenSet[PredicateInputType] = frozenset([PredicateInputType.TIME_RANGE_CONSTRAINT]) + where_filter_specs: Sequence[WhereFilterSpec] + pushdown_enabled_types: FrozenSet[PredicateInputType] = frozenset( + [PredicateInputType.TIME_RANGE_CONSTRAINT, PredicateInputType.CATEGORICAL_DIMENSION] + ) def __post_init__(self) -> None: """Validation to ensure pushdown states are configured correctly. @@ -107,13 +112,12 @@ def __post_init__(self) -> None: invalid_types: Set[PredicateInputType] = set() for input_type in self.pushdown_enabled_types: - if ( + if input_type is PredicateInputType.ENTITY or input_type is PredicateInputType.TIME_DIMENSION: + invalid_types.add(input_type) + elif ( input_type is PredicateInputType.CATEGORICAL_DIMENSION - or input_type is PredicateInputType.ENTITY - or input_type is PredicateInputType.TIME_DIMENSION + or input_type is PredicateInputType.TIME_RANGE_CONSTRAINT ): - invalid_types.add(input_type) - elif input_type is PredicateInputType.TIME_RANGE_CONSTRAINT: continue else: assert_values_exhausted(input_type) @@ -125,23 +129,24 @@ def __post_init__(self) -> None: f"for {self.pushdown_enabled_types}, which includes the following invalid types: {invalid_types}." ) - # TODO: Include where filter specs when they are added to this class time_range_constraint_is_valid = ( self.time_range_constraint is None or PredicateInputType.TIME_RANGE_CONSTRAINT in self.pushdown_enabled_types ) - assert time_range_constraint_is_valid, ( + where_filter_specs_are_valid = len(self.where_filter_specs) == 0 or self.where_filter_pushdown_enabled + assert time_range_constraint_is_valid and where_filter_specs_are_valid, ( "Invalid pushdown state configuration! Disabled pushdown state objects cannot have properties " "set that may lead to improper access and use in other contexts, as that can lead to unintended " "filtering operations in cases where these properties are accessed without appropriate checks against " - "pushdown configuration. The following properties should all have None values:\n" - f"time_range_constraint: {self.time_range_constraint}" + "pushdown configuration. The following properties should be None or empty:\n" + f"time_range_constraint: {self.time_range_constraint}\n" + f"where_filter_specs: {self.where_filter_specs}" ) @property def has_pushdown_potential(self) -> bool: """Returns whether or not pushdown is enabled for a type with predicate candidates in place.""" - return self.has_time_range_constraint_to_push_down + return self.has_time_range_constraint_to_push_down or self.has_where_filters_to_push_down @property def has_time_range_constraint_to_push_down(self) -> bool: @@ -156,6 +161,44 @@ def has_time_range_constraint_to_push_down(self) -> bool: and self.time_range_constraint is not None ) + @property + def has_where_filters_to_push_down(self) -> bool: + """Convenience accessor for checking if there are any where filters to push down.""" + return self.where_filter_pushdown_enabled and len(self.where_filter_specs) > 0 + + @property + def where_filter_pushdown_enabled(self) -> bool: + """Indicates whether or not pushdown is enabled for where filters.""" + return ( + PredicateInputType.CATEGORICAL_DIMENSION in self.pushdown_enabled_types + or PredicateInputType.ENTITY in self.pushdown_enabled_types + or PredicateInputType.TIME_DIMENSION in self.pushdown_enabled_types + ) + + @property + def pushdown_eligible_element_types(self) -> FrozenSet[LinkableElementType]: + """Set of linkable element types eligible for predicate pushdown. + + This converts from enabled PushdownInputTypes for checking if linkable elements in where filter specs are + eligible for pushdown. + """ + eligible_types: List[LinkableElementType] = [] + for enabled_type in self.pushdown_enabled_types: + if enabled_type is PredicateInputType.TIME_RANGE_CONSTRAINT: + pass + elif enabled_type is PredicateInputType.CATEGORICAL_DIMENSION: + eligible_types.append(LinkableElementType.DIMENSION) + elif enabled_type is PredicateInputType.TIME_DIMENSION or enabled_type is PredicateInputType.ENTITY: + # TODO: Remove as support for time dimensions and entities becomes available + raise NotImplementedError( + "Predicate pushdown is not currently supported for where filter predicates with time dimension or " + f"entity references, but this pushdown state is enabled for {enabled_type}." + ) + else: + assert_values_exhausted(enabled_type) + + return frozenset(eligible_types) + @staticmethod def with_time_range_constraint( original_pushdown_state: PredicatePushdownState, time_range_constraint: TimeRangeConstraint @@ -169,7 +212,9 @@ def with_time_range_constraint( {PredicateInputType.TIME_RANGE_CONSTRAINT} ) return PredicatePushdownState( - time_range_constraint=time_range_constraint, pushdown_enabled_types=pushdown_enabled_types + time_range_constraint=time_range_constraint, + pushdown_enabled_types=pushdown_enabled_types, + where_filter_specs=original_pushdown_state.where_filter_specs, ) @staticmethod @@ -180,7 +225,27 @@ def without_time_range_constraint( pushdown_enabled_types = original_pushdown_state.pushdown_enabled_types.difference( {PredicateInputType.TIME_RANGE_CONSTRAINT} ) - return PredicatePushdownState(time_range_constraint=None, pushdown_enabled_types=pushdown_enabled_types) + return PredicatePushdownState( + time_range_constraint=None, + pushdown_enabled_types=pushdown_enabled_types, + where_filter_specs=original_pushdown_state.where_filter_specs, + ) + + @staticmethod + def with_additional_where_filter_specs( + original_pushdown_state: PredicatePushdownState, additional_where_filter_specs: Sequence[WhereFilterSpec] + ) -> PredicatePushdownState: + """Factory method for adding additional WhereFilterSpecs for pushdown operations. + + This requires that the PushdownState allow for where filters - time range only or disabled states will + raise an exception, and must be checked externally. + """ + updated_where_specs = tuple(original_pushdown_state.where_filter_specs) + tuple(additional_where_filter_specs) + return PredicatePushdownState( + time_range_constraint=original_pushdown_state.time_range_constraint, + where_filter_specs=updated_where_specs, + pushdown_enabled_types=original_pushdown_state.pushdown_enabled_types, + ) @staticmethod def with_pushdown_disabled() -> PredicatePushdownState: @@ -194,6 +259,7 @@ def with_pushdown_disabled() -> PredicatePushdownState: return PredicatePushdownState( time_range_constraint=None, pushdown_enabled_types=frozenset(), + where_filter_specs=tuple(), ) @@ -240,6 +306,13 @@ def apply_matching_filter_predicates( time_range_constraint=predicate_pushdown_state.time_range_constraint, ) + if predicate_pushdown_state.has_where_filters_to_push_down: + source_nodes = self._add_where_constraint( + source_nodes=source_nodes, + where_filter_specs=predicate_pushdown_state.where_filter_specs, + enabled_element_types=predicate_pushdown_state.pushdown_eligible_element_types, + ) + return source_nodes def _add_time_range_constraint( @@ -272,6 +345,48 @@ def _add_time_range_constraint( processed_nodes.append(source_node) return processed_nodes + def _add_where_constraint( + self, + source_nodes: Sequence[DataflowPlanNode], + where_filter_specs: Sequence[WhereFilterSpec], + enabled_element_types: FrozenSet[LinkableElementType], + ) -> Sequence[DataflowPlanNode]: + """Processes where filter specs and evaluates their fitness for pushdown against the provided node set.""" + eligible_filter_specs_by_model: Dict[SemanticModelReference, Sequence[WhereFilterSpec]] = {} + for spec in where_filter_specs: + semantic_models = set(element.semantic_model_origin for element in spec.linkable_elements) + invalid_element_types = [ + element for element in spec.linkable_elements if element.element_type not in enabled_element_types + ] + if len(semantic_models) == 1 and len(invalid_element_types) == 0: + model = semantic_models.pop() + eligible_filter_specs_by_model[model] = tuple(eligible_filter_specs_by_model.get(model, tuple())) + ( + spec, + ) + + filtered_nodes: List[DataflowPlanNode] = [] + for source_node in source_nodes: + node_semantic_models = tuple(source_node.as_plan().source_semantic_models) + if len(node_semantic_models) == 1 and node_semantic_models[0] in eligible_filter_specs_by_model: + eligible_filter_specs = eligible_filter_specs_by_model[node_semantic_models[0]] + source_node_specs = self._node_data_set_resolver.get_output_data_set(source_node).instance_set.spec_set + matching_filter_specs = [ + filter_spec + for filter_spec in eligible_filter_specs + if all([spec in source_node_specs.linkable_specs for spec in filter_spec.linkable_specs]) + ] + if len(matching_filter_specs) == 0: + filtered_nodes.append(source_node) + else: + where_constraint = WhereFilterSpec.merge_iterable(matching_filter_specs) + filtered_nodes.append( + WhereConstraintNode(parent_node=source_node, where_constraint=where_constraint) + ) + else: + filtered_nodes.append(source_node) + + return filtered_nodes + def _node_contains_entity( self, node: DataflowPlanNode, diff --git a/tests_metricflow/dataflow/builder/test_predicate_pushdown.py b/tests_metricflow/dataflow/builder/test_predicate_pushdown.py index ff385fe1b6..a3cc4e3e4b 100644 --- a/tests_metricflow/dataflow/builder/test_predicate_pushdown.py +++ b/tests_metricflow/dataflow/builder/test_predicate_pushdown.py @@ -9,9 +9,7 @@ @pytest.fixture def fully_enabled_pushdown_state() -> PredicatePushdownState: """Tests a valid configuration with all predicate properties set and pushdown fully enabled.""" - params = PredicatePushdownState( - time_range_constraint=TimeRangeConstraint.all_time(), - ) + params = PredicatePushdownState(time_range_constraint=TimeRangeConstraint.all_time(), where_filter_specs=tuple()) return params @@ -20,6 +18,7 @@ def test_time_range_pushdown_enabled_states(fully_enabled_pushdown_state: Predic time_range_only_state = PredicatePushdownState( time_range_constraint=TimeRangeConstraint.all_time(), pushdown_enabled_types=frozenset([PredicateInputType.TIME_RANGE_CONSTRAINT]), + where_filter_specs=tuple(), ) enabled_states = { @@ -39,4 +38,8 @@ def test_time_range_pushdown_enabled_states(fully_enabled_pushdown_state: Predic def test_invalid_disabled_pushdown_state() -> None: """Tests checks for invalid param configuration on disabled pushdown parameters.""" with pytest.raises(AssertionError, match="Disabled pushdown state objects cannot have properties set"): - PredicatePushdownState(time_range_constraint=TimeRangeConstraint.all_time(), pushdown_enabled_types=frozenset()) + PredicatePushdownState( + time_range_constraint=TimeRangeConstraint.all_time(), + pushdown_enabled_types=frozenset(), + where_filter_specs=tuple(), + ) diff --git a/tests_metricflow/query_rendering/test_predicate_pushdown_rendering.py b/tests_metricflow/query_rendering/test_predicate_pushdown_rendering.py new file mode 100644 index 0000000000..0018541dfc --- /dev/null +++ b/tests_metricflow/query_rendering/test_predicate_pushdown_rendering.py @@ -0,0 +1,136 @@ +from __future__ import annotations + +import pytest +from _pytest.fixtures import FixtureRequest +from dbt_semantic_interfaces.implementations.filters.where_filter import PydanticWhereFilter +from metricflow_semantics.query.query_parser import MetricFlowQueryParser +from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration + +from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder +from metricflow.plan_conversion.dataflow_to_sql import DataflowToSqlQueryPlanConverter +from metricflow.protocols.sql_client import SqlClient +from tests_metricflow.query_rendering.compare_rendered_query import convert_and_check + + +@pytest.mark.sql_engine_snapshot +def test_single_categorical_dimension_pushdown( + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + dataflow_plan_builder: DataflowPlanBuilder, + query_parser: MetricFlowQueryParser, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, +) -> None: + """Tests rendering a query where we expect predicate pushdown for a single categorical dimension.""" + parsed_query = query_parser.parse_and_validate_query( + metric_names=("bookings",), + group_by_names=("listing__country_latest",), + where_constraint=PydanticWhereFilter( + where_sql_template="{{ Dimension('booking__is_instant') }}", + ), + ) + dataflow_plan = dataflow_plan_builder.build_plan(parsed_query.query_spec) + + convert_and_check( + request=request, + mf_test_configuration=mf_test_configuration, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + node=dataflow_plan.sink_node, + ) + + +@pytest.mark.sql_engine_snapshot +def test_multiple_categorical_dimension_pushdown( + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + dataflow_plan_builder: DataflowPlanBuilder, + query_parser: MetricFlowQueryParser, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, +) -> None: + """Tests rendering a query where we expect predicate pushdown for more than one categorical dimension.""" + parsed_query = query_parser.parse_and_validate_query( + metric_names=("listings",), + group_by_names=("user__home_state_latest",), + where_constraint=PydanticWhereFilter( + where_sql_template="{{ Dimension('listing__is_lux_latest') }} OR {{ Dimension('listing__capacity_latest') }} > 4", + ), + ) + dataflow_plan = dataflow_plan_builder.build_plan(parsed_query.query_spec) + + convert_and_check( + request=request, + mf_test_configuration=mf_test_configuration, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + node=dataflow_plan.sink_node, + ) + + +@pytest.mark.sql_engine_snapshot +def test_different_filters_on_same_measure_source_categorical_dimension( + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + dataflow_plan_builder: DataflowPlanBuilder, + query_parser: MetricFlowQueryParser, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, +) -> None: + """Tests rendering a query where multiple filters against the same measure dimension need to be an effective OR. + + This can be an issue where a derived metric takes in two filters that refer to the same dimension from the input + measure source. If these filters are disjoint the predicate pushdown needs to ensure that all matching rows are + returned, so we cannot simply push one filter or the other down, nor can we push them down as an AND - they + must be an OR, since all relevant rows need to be returned to the requesting metrics. + + The metric listed here has one input that filters on bookings__is_instant and another that does not, which means + the source input for the latter input must NOT have the filter applied to it. + """ + parsed_query = query_parser.parse_and_validate_query( + metric_names=("instant_booking_fraction_of_max_value",), + group_by_names=("metric_time",), + ) + dataflow_plan = dataflow_plan_builder.build_plan(parsed_query.query_spec) + + convert_and_check( + request=request, + mf_test_configuration=mf_test_configuration, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + node=dataflow_plan.sink_node, + ) + + +@pytest.mark.sql_engine_snapshot +def test_skipped_pushdown( + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + dataflow_plan_builder: DataflowPlanBuilder, + query_parser: MetricFlowQueryParser, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, +) -> None: + """Tests rendering a query where we expect to skip predicate pushdown because it is unsafe. + + This is the query rendering test for the scenarios where the push down evaluation indicates that we should + skip pushdown, typically due to a lack of certainty over whether or not the query will return the same results. + + The specific scenario is less important here than that it match one that should not be pushed down. + """ + parsed_query = query_parser.parse_and_validate_query( + metric_names=("bookings",), + group_by_names=("listing__country_latest",), + where_constraint=PydanticWhereFilter( + where_sql_template="{{ Dimension('booking__is_instant') }} OR {{ Dimension('listing__is_lux_latest') }}", + ), + ) + dataflow_plan = dataflow_plan_builder.build_plan(parsed_query.query_spec) + + convert_and_check( + request=request, + mf_test_configuration=mf_test_configuration, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + node=dataflow_plan.sink_node, + ) diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_dimensions_with_time_constraint__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_dimensions_with_time_constraint__dfp_0.xml index 95e5e4a303..415f19bcf2 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_dimensions_with_time_constraint__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_dimensions_with_time_constraint__dfp_0.xml @@ -11,7 +11,7 @@ - + diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml index dacb8f92cf..b54d7bf0be 100644 --- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_measure_constraint_with_reused_measure_plan__dfp_0.xml @@ -58,7 +58,7 @@ - + @@ -100,16 +100,53 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0.sql index 510d1145cd..8d2cef8941 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_18.average_booking_value) AS average_booking_value + , MAX(subq_31.bookings) AS bookings + , MAX(subq_39.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_17.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_16.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_15.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_14.booking__is_instant + , subq_14.listing__is_lux_latest + , subq_14.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_13.booking__is_instant + , subq_13.listing__is_lux_latest + , subq_13.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.is_lux_latest AS listing__is_lux_latest + , subq_9.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_8.listing + , subq_8.booking__is_instant + , subq_8.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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__day + , 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 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_11.listing + , subq_11.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_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.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ 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_3 - ) subq_4 - ) subq_5 + ) subq_10 + ) subq_11 + ) subq_12 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_15 + ) subq_16 + ) subq_17 + ) subq_18 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_30.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_29.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_28.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_27.booking__is_instant + , subq_27.listing__is_lux_latest + , subq_27.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_22.listing AS listing + , subq_22.booking__is_instant AS booking__is_instant + , subq_25.is_lux_latest AS listing__is_lux_latest + , subq_22.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_21.listing + , subq_21.booking__is_instant + , subq_21.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_20.ds_partitioned__week + , subq_20.ds_partitioned__month + , subq_20.ds_partitioned__quarter + , subq_20.ds_partitioned__year + , subq_20.ds_partitioned__extract_year + , subq_20.ds_partitioned__extract_quarter + , subq_20.ds_partitioned__extract_month + , subq_20.ds_partitioned__extract_day + , subq_20.ds_partitioned__extract_dow + , subq_20.ds_partitioned__extract_doy + , subq_20.paid_at__day + , subq_20.paid_at__week + , subq_20.paid_at__month + , subq_20.paid_at__quarter + , subq_20.paid_at__year + , subq_20.paid_at__extract_year + , subq_20.paid_at__extract_quarter + , subq_20.paid_at__extract_month + , subq_20.paid_at__extract_day + , subq_20.paid_at__extract_dow + , subq_20.paid_at__extract_doy + , subq_20.booking__ds__day + , subq_20.booking__ds__week + , subq_20.booking__ds__month + , subq_20.booking__ds__quarter + , subq_20.booking__ds__year + , subq_20.booking__ds__extract_year + , subq_20.booking__ds__extract_quarter + , subq_20.booking__ds__extract_month + , subq_20.booking__ds__extract_day + , subq_20.booking__ds__extract_dow + , subq_20.booking__ds__extract_doy + , subq_20.booking__ds_partitioned__day + , subq_20.booking__ds_partitioned__week + , subq_20.booking__ds_partitioned__month + , subq_20.booking__ds_partitioned__quarter + , subq_20.booking__ds_partitioned__year + , subq_20.booking__ds_partitioned__extract_year + , subq_20.booking__ds_partitioned__extract_quarter + , subq_20.booking__ds_partitioned__extract_month + , subq_20.booking__ds_partitioned__extract_day + , subq_20.booking__ds_partitioned__extract_dow + , subq_20.booking__ds_partitioned__extract_doy + , subq_20.booking__paid_at__day + , subq_20.booking__paid_at__week + , subq_20.booking__paid_at__month + , subq_20.booking__paid_at__quarter + , subq_20.booking__paid_at__year + , subq_20.booking__paid_at__extract_year + , subq_20.booking__paid_at__extract_quarter + , subq_20.booking__paid_at__extract_month + , subq_20.booking__paid_at__extract_day + , subq_20.booking__paid_at__extract_dow + , subq_20.booking__paid_at__extract_doy + , subq_20.metric_time__day + , subq_20.metric_time__week + , subq_20.metric_time__month + , subq_20.metric_time__quarter + , subq_20.metric_time__year + , subq_20.metric_time__extract_year + , subq_20.metric_time__extract_quarter + , subq_20.metric_time__extract_month + , subq_20.metric_time__extract_day + , subq_20.metric_time__extract_dow + , subq_20.metric_time__extract_doy + , subq_20.listing + , subq_20.guest + , subq_20.host + , subq_20.booking__listing + , subq_20.booking__guest + , subq_20.booking__host + , subq_20.is_instant + , subq_20.booking__is_instant + , subq_20.bookings + , subq_20.instant_bookings + , subq_20.booking_value + , subq_20.max_booking_value + , subq_20.min_booking_value + , subq_20.bookers + , subq_20.average_booking_value + , subq_20.referred_bookings + , subq_20.median_booking_value + , subq_20.booking_value_p99 + , subq_20.discrete_booking_value_p99 + , subq_20.approximate_continuous_booking_value_p99 + , subq_20.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_12 - ) subq_13 - ) subq_14 + 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.ds__day AS metric_time__day + , subq_19.ds__week AS metric_time__week + , subq_19.ds__month AS metric_time__month + , subq_19.ds__quarter AS metric_time__quarter + , subq_19.ds__year AS metric_time__year + , subq_19.ds__extract_year AS metric_time__extract_year + , subq_19.ds__extract_quarter AS metric_time__extract_quarter + , subq_19.ds__extract_month AS metric_time__extract_month + , subq_19.ds__extract_day AS metric_time__extract_day + , subq_19.ds__extract_dow AS metric_time__extract_dow + , subq_19.ds__extract_doy AS metric_time__extract_doy + , 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.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 ( + -- 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_19 + ) subq_20 + WHERE booking__is_instant + ) subq_21 + ) subq_22 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_24.listing + , subq_24.is_lux_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_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.created_at__day + , subq_23.created_at__week + , subq_23.created_at__month + , subq_23.created_at__quarter + , subq_23.created_at__year + , subq_23.created_at__extract_year + , subq_23.created_at__extract_quarter + , subq_23.created_at__extract_month + , subq_23.created_at__extract_day + , subq_23.created_at__extract_dow + , subq_23.created_at__extract_doy + , subq_23.listing__ds__day + , subq_23.listing__ds__week + , subq_23.listing__ds__month + , subq_23.listing__ds__quarter + , subq_23.listing__ds__year + , subq_23.listing__ds__extract_year + , subq_23.listing__ds__extract_quarter + , subq_23.listing__ds__extract_month + , subq_23.listing__ds__extract_day + , subq_23.listing__ds__extract_dow + , subq_23.listing__ds__extract_doy + , subq_23.listing__created_at__day + , subq_23.listing__created_at__week + , subq_23.listing__created_at__month + , subq_23.listing__created_at__quarter + , subq_23.listing__created_at__year + , subq_23.listing__created_at__extract_year + , subq_23.listing__created_at__extract_quarter + , subq_23.listing__created_at__extract_month + , subq_23.listing__created_at__extract_day + , subq_23.listing__created_at__extract_dow + , subq_23.listing__created_at__extract_doy + , subq_23.ds__day AS metric_time__day + , subq_23.ds__week AS metric_time__week + , subq_23.ds__month AS metric_time__month + , subq_23.ds__quarter AS metric_time__quarter + , subq_23.ds__year AS metric_time__year + , subq_23.ds__extract_year AS metric_time__extract_year + , subq_23.ds__extract_quarter AS metric_time__extract_quarter + , subq_23.ds__extract_month AS metric_time__extract_month + , subq_23.ds__extract_day AS metric_time__extract_day + , subq_23.ds__extract_dow AS metric_time__extract_dow + , subq_23.ds__extract_doy AS metric_time__extract_doy + , subq_23.listing + , subq_23.user + , subq_23.listing__user + , subq_23.country_latest + , subq_23.is_lux_latest + , subq_23.capacity_latest + , subq_23.listing__country_latest + , subq_23.listing__is_lux_latest + , subq_23.listing__capacity_latest + , subq_23.listings + , subq_23.largest_listing + , subq_23.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ 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_23 + ) subq_24 + ) subq_25 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_22.listing = subq_25.listing + ) subq_26 + ) subq_27 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_28 + ) subq_29 + ) subq_30 + ) subq_31 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_38.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_37.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_36.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_35.booking__is_instant + , subq_35.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_34.booking__is_instant + , subq_34.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_33.ds__day + , subq_33.ds__week + , subq_33.ds__month + , subq_33.ds__quarter + , subq_33.ds__year + , subq_33.ds__extract_year + , subq_33.ds__extract_quarter + , subq_33.ds__extract_month + , subq_33.ds__extract_day + , subq_33.ds__extract_dow + , subq_33.ds__extract_doy + , subq_33.ds_partitioned__day + , subq_33.ds_partitioned__week + , subq_33.ds_partitioned__month + , subq_33.ds_partitioned__quarter + , subq_33.ds_partitioned__year + , subq_33.ds_partitioned__extract_year + , subq_33.ds_partitioned__extract_quarter + , subq_33.ds_partitioned__extract_month + , subq_33.ds_partitioned__extract_day + , subq_33.ds_partitioned__extract_dow + , subq_33.ds_partitioned__extract_doy + , subq_33.paid_at__day + , subq_33.paid_at__week + , subq_33.paid_at__month + , subq_33.paid_at__quarter + , subq_33.paid_at__year + , subq_33.paid_at__extract_year + , subq_33.paid_at__extract_quarter + , subq_33.paid_at__extract_month + , subq_33.paid_at__extract_day + , subq_33.paid_at__extract_dow + , subq_33.paid_at__extract_doy + , subq_33.booking__ds__day + , subq_33.booking__ds__week + , subq_33.booking__ds__month + , subq_33.booking__ds__quarter + , subq_33.booking__ds__year + , subq_33.booking__ds__extract_year + , subq_33.booking__ds__extract_quarter + , subq_33.booking__ds__extract_month + , subq_33.booking__ds__extract_day + , subq_33.booking__ds__extract_dow + , subq_33.booking__ds__extract_doy + , subq_33.booking__ds_partitioned__day + , subq_33.booking__ds_partitioned__week + , subq_33.booking__ds_partitioned__month + , subq_33.booking__ds_partitioned__quarter + , subq_33.booking__ds_partitioned__year + , subq_33.booking__ds_partitioned__extract_year + , subq_33.booking__ds_partitioned__extract_quarter + , subq_33.booking__ds_partitioned__extract_month + , subq_33.booking__ds_partitioned__extract_day + , subq_33.booking__ds_partitioned__extract_dow + , subq_33.booking__ds_partitioned__extract_doy + , subq_33.booking__paid_at__day + , subq_33.booking__paid_at__week + , subq_33.booking__paid_at__month + , subq_33.booking__paid_at__quarter + , subq_33.booking__paid_at__year + , subq_33.booking__paid_at__extract_year + , subq_33.booking__paid_at__extract_quarter + , subq_33.booking__paid_at__extract_month + , subq_33.booking__paid_at__extract_day + , subq_33.booking__paid_at__extract_dow + , subq_33.booking__paid_at__extract_doy + , subq_33.metric_time__day + , subq_33.metric_time__week + , subq_33.metric_time__month + , subq_33.metric_time__quarter + , subq_33.metric_time__year + , subq_33.metric_time__extract_year + , subq_33.metric_time__extract_quarter + , subq_33.metric_time__extract_month + , subq_33.metric_time__extract_day + , subq_33.metric_time__extract_dow + , subq_33.metric_time__extract_doy + , subq_33.listing + , subq_33.guest + , subq_33.host + , subq_33.booking__listing + , subq_33.booking__guest + , subq_33.booking__host + , subq_33.is_instant + , subq_33.booking__is_instant + , subq_33.bookings + , subq_33.instant_bookings + , subq_33.booking_value + , subq_33.max_booking_value + , subq_33.min_booking_value + , subq_33.bookers + , subq_33.average_booking_value + , subq_33.referred_bookings + , subq_33.median_booking_value + , subq_33.booking_value_p99 + , subq_33.discrete_booking_value_p99 + , subq_33.approximate_continuous_booking_value_p99 + , subq_33.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_24 - ) subq_25 - ) subq_26 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.ds__day AS metric_time__day + , subq_32.ds__week AS metric_time__week + , subq_32.ds__month AS metric_time__month + , subq_32.ds__quarter AS metric_time__quarter + , subq_32.ds__year AS metric_time__year + , subq_32.ds__extract_year AS metric_time__extract_year + , subq_32.ds__extract_quarter AS metric_time__extract_quarter + , subq_32.ds__extract_month AS metric_time__extract_month + , subq_32.ds__extract_day AS metric_time__extract_day + , subq_32.ds__extract_dow AS metric_time__extract_dow + , subq_32.ds__extract_doy AS metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 + 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_32 + ) subq_33 + WHERE booking__is_instant + ) subq_34 + ) subq_35 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_36 + ) subq_37 + ) subq_38 + ) subq_39 + ) subq_40 +) subq_41 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0_optimized.sql index a73bfea928..60a09b752b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_54.average_booking_value) AS average_booking_value + , MAX(subq_67.bookings) AS bookings + , MAX(subq_75.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_45.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_45.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_43 + WHERE booking__is_instant + ) subq_45 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_45.listing = listings_latest_src_28000.listing_id + ) subq_50 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_54 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_58.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_58.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_56 + WHERE booking__is_instant + ) subq_58 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_58.listing = listings_latest_src_28000.listing_id + ) subq_63 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_67 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_69 + WHERE booking__is_instant + ) subq_71 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_75 + ) subq_76 +) subq_77 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0.sql index 94ca50b1fd..9654a4d454 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_18.average_booking_value) AS average_booking_value + , MAX(subq_31.bookings) AS bookings + , MAX(subq_39.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_17.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_16.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_15.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_14.booking__is_instant + , subq_14.listing__is_lux_latest + , subq_14.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_13.booking__is_instant + , subq_13.listing__is_lux_latest + , subq_13.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.is_lux_latest AS listing__is_lux_latest + , subq_9.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_8.listing + , subq_8.booking__is_instant + , subq_8.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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__day + , 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 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_11.listing + , subq_11.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_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.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ 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_3 - ) subq_4 - ) subq_5 + ) subq_10 + ) subq_11 + ) subq_12 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_15 + ) subq_16 + ) subq_17 + ) subq_18 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_30.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_29.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_28.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_27.booking__is_instant + , subq_27.listing__is_lux_latest + , subq_27.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_22.listing AS listing + , subq_22.booking__is_instant AS booking__is_instant + , subq_25.is_lux_latest AS listing__is_lux_latest + , subq_22.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_21.listing + , subq_21.booking__is_instant + , subq_21.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_20.ds_partitioned__week + , subq_20.ds_partitioned__month + , subq_20.ds_partitioned__quarter + , subq_20.ds_partitioned__year + , subq_20.ds_partitioned__extract_year + , subq_20.ds_partitioned__extract_quarter + , subq_20.ds_partitioned__extract_month + , subq_20.ds_partitioned__extract_day + , subq_20.ds_partitioned__extract_dow + , subq_20.ds_partitioned__extract_doy + , subq_20.paid_at__day + , subq_20.paid_at__week + , subq_20.paid_at__month + , subq_20.paid_at__quarter + , subq_20.paid_at__year + , subq_20.paid_at__extract_year + , subq_20.paid_at__extract_quarter + , subq_20.paid_at__extract_month + , subq_20.paid_at__extract_day + , subq_20.paid_at__extract_dow + , subq_20.paid_at__extract_doy + , subq_20.booking__ds__day + , subq_20.booking__ds__week + , subq_20.booking__ds__month + , subq_20.booking__ds__quarter + , subq_20.booking__ds__year + , subq_20.booking__ds__extract_year + , subq_20.booking__ds__extract_quarter + , subq_20.booking__ds__extract_month + , subq_20.booking__ds__extract_day + , subq_20.booking__ds__extract_dow + , subq_20.booking__ds__extract_doy + , subq_20.booking__ds_partitioned__day + , subq_20.booking__ds_partitioned__week + , subq_20.booking__ds_partitioned__month + , subq_20.booking__ds_partitioned__quarter + , subq_20.booking__ds_partitioned__year + , subq_20.booking__ds_partitioned__extract_year + , subq_20.booking__ds_partitioned__extract_quarter + , subq_20.booking__ds_partitioned__extract_month + , subq_20.booking__ds_partitioned__extract_day + , subq_20.booking__ds_partitioned__extract_dow + , subq_20.booking__ds_partitioned__extract_doy + , subq_20.booking__paid_at__day + , subq_20.booking__paid_at__week + , subq_20.booking__paid_at__month + , subq_20.booking__paid_at__quarter + , subq_20.booking__paid_at__year + , subq_20.booking__paid_at__extract_year + , subq_20.booking__paid_at__extract_quarter + , subq_20.booking__paid_at__extract_month + , subq_20.booking__paid_at__extract_day + , subq_20.booking__paid_at__extract_dow + , subq_20.booking__paid_at__extract_doy + , subq_20.metric_time__day + , subq_20.metric_time__week + , subq_20.metric_time__month + , subq_20.metric_time__quarter + , subq_20.metric_time__year + , subq_20.metric_time__extract_year + , subq_20.metric_time__extract_quarter + , subq_20.metric_time__extract_month + , subq_20.metric_time__extract_day + , subq_20.metric_time__extract_dow + , subq_20.metric_time__extract_doy + , subq_20.listing + , subq_20.guest + , subq_20.host + , subq_20.booking__listing + , subq_20.booking__guest + , subq_20.booking__host + , subq_20.is_instant + , subq_20.booking__is_instant + , subq_20.bookings + , subq_20.instant_bookings + , subq_20.booking_value + , subq_20.max_booking_value + , subq_20.min_booking_value + , subq_20.bookers + , subq_20.average_booking_value + , subq_20.referred_bookings + , subq_20.median_booking_value + , subq_20.booking_value_p99 + , subq_20.discrete_booking_value_p99 + , subq_20.approximate_continuous_booking_value_p99 + , subq_20.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_12 - ) subq_13 - ) subq_14 + 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.ds__day AS metric_time__day + , subq_19.ds__week AS metric_time__week + , subq_19.ds__month AS metric_time__month + , subq_19.ds__quarter AS metric_time__quarter + , subq_19.ds__year AS metric_time__year + , subq_19.ds__extract_year AS metric_time__extract_year + , subq_19.ds__extract_quarter AS metric_time__extract_quarter + , subq_19.ds__extract_month AS metric_time__extract_month + , subq_19.ds__extract_day AS metric_time__extract_day + , subq_19.ds__extract_dow AS metric_time__extract_dow + , subq_19.ds__extract_doy AS metric_time__extract_doy + , 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.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 ( + -- 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_19 + ) subq_20 + WHERE booking__is_instant + ) subq_21 + ) subq_22 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_24.listing + , subq_24.is_lux_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_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.created_at__day + , subq_23.created_at__week + , subq_23.created_at__month + , subq_23.created_at__quarter + , subq_23.created_at__year + , subq_23.created_at__extract_year + , subq_23.created_at__extract_quarter + , subq_23.created_at__extract_month + , subq_23.created_at__extract_day + , subq_23.created_at__extract_dow + , subq_23.created_at__extract_doy + , subq_23.listing__ds__day + , subq_23.listing__ds__week + , subq_23.listing__ds__month + , subq_23.listing__ds__quarter + , subq_23.listing__ds__year + , subq_23.listing__ds__extract_year + , subq_23.listing__ds__extract_quarter + , subq_23.listing__ds__extract_month + , subq_23.listing__ds__extract_day + , subq_23.listing__ds__extract_dow + , subq_23.listing__ds__extract_doy + , subq_23.listing__created_at__day + , subq_23.listing__created_at__week + , subq_23.listing__created_at__month + , subq_23.listing__created_at__quarter + , subq_23.listing__created_at__year + , subq_23.listing__created_at__extract_year + , subq_23.listing__created_at__extract_quarter + , subq_23.listing__created_at__extract_month + , subq_23.listing__created_at__extract_day + , subq_23.listing__created_at__extract_dow + , subq_23.listing__created_at__extract_doy + , subq_23.ds__day AS metric_time__day + , subq_23.ds__week AS metric_time__week + , subq_23.ds__month AS metric_time__month + , subq_23.ds__quarter AS metric_time__quarter + , subq_23.ds__year AS metric_time__year + , subq_23.ds__extract_year AS metric_time__extract_year + , subq_23.ds__extract_quarter AS metric_time__extract_quarter + , subq_23.ds__extract_month AS metric_time__extract_month + , subq_23.ds__extract_day AS metric_time__extract_day + , subq_23.ds__extract_dow AS metric_time__extract_dow + , subq_23.ds__extract_doy AS metric_time__extract_doy + , subq_23.listing + , subq_23.user + , subq_23.listing__user + , subq_23.country_latest + , subq_23.is_lux_latest + , subq_23.capacity_latest + , subq_23.listing__country_latest + , subq_23.listing__is_lux_latest + , subq_23.listing__capacity_latest + , subq_23.listings + , subq_23.largest_listing + , subq_23.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ 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_23 + ) subq_24 + ) subq_25 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_22.listing = subq_25.listing + ) subq_26 + ) subq_27 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_28 + ) subq_29 + ) subq_30 + ) subq_31 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_38.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_37.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_36.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_35.booking__is_instant + , subq_35.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_34.booking__is_instant + , subq_34.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_33.ds__day + , subq_33.ds__week + , subq_33.ds__month + , subq_33.ds__quarter + , subq_33.ds__year + , subq_33.ds__extract_year + , subq_33.ds__extract_quarter + , subq_33.ds__extract_month + , subq_33.ds__extract_day + , subq_33.ds__extract_dow + , subq_33.ds__extract_doy + , subq_33.ds_partitioned__day + , subq_33.ds_partitioned__week + , subq_33.ds_partitioned__month + , subq_33.ds_partitioned__quarter + , subq_33.ds_partitioned__year + , subq_33.ds_partitioned__extract_year + , subq_33.ds_partitioned__extract_quarter + , subq_33.ds_partitioned__extract_month + , subq_33.ds_partitioned__extract_day + , subq_33.ds_partitioned__extract_dow + , subq_33.ds_partitioned__extract_doy + , subq_33.paid_at__day + , subq_33.paid_at__week + , subq_33.paid_at__month + , subq_33.paid_at__quarter + , subq_33.paid_at__year + , subq_33.paid_at__extract_year + , subq_33.paid_at__extract_quarter + , subq_33.paid_at__extract_month + , subq_33.paid_at__extract_day + , subq_33.paid_at__extract_dow + , subq_33.paid_at__extract_doy + , subq_33.booking__ds__day + , subq_33.booking__ds__week + , subq_33.booking__ds__month + , subq_33.booking__ds__quarter + , subq_33.booking__ds__year + , subq_33.booking__ds__extract_year + , subq_33.booking__ds__extract_quarter + , subq_33.booking__ds__extract_month + , subq_33.booking__ds__extract_day + , subq_33.booking__ds__extract_dow + , subq_33.booking__ds__extract_doy + , subq_33.booking__ds_partitioned__day + , subq_33.booking__ds_partitioned__week + , subq_33.booking__ds_partitioned__month + , subq_33.booking__ds_partitioned__quarter + , subq_33.booking__ds_partitioned__year + , subq_33.booking__ds_partitioned__extract_year + , subq_33.booking__ds_partitioned__extract_quarter + , subq_33.booking__ds_partitioned__extract_month + , subq_33.booking__ds_partitioned__extract_day + , subq_33.booking__ds_partitioned__extract_dow + , subq_33.booking__ds_partitioned__extract_doy + , subq_33.booking__paid_at__day + , subq_33.booking__paid_at__week + , subq_33.booking__paid_at__month + , subq_33.booking__paid_at__quarter + , subq_33.booking__paid_at__year + , subq_33.booking__paid_at__extract_year + , subq_33.booking__paid_at__extract_quarter + , subq_33.booking__paid_at__extract_month + , subq_33.booking__paid_at__extract_day + , subq_33.booking__paid_at__extract_dow + , subq_33.booking__paid_at__extract_doy + , subq_33.metric_time__day + , subq_33.metric_time__week + , subq_33.metric_time__month + , subq_33.metric_time__quarter + , subq_33.metric_time__year + , subq_33.metric_time__extract_year + , subq_33.metric_time__extract_quarter + , subq_33.metric_time__extract_month + , subq_33.metric_time__extract_day + , subq_33.metric_time__extract_dow + , subq_33.metric_time__extract_doy + , subq_33.listing + , subq_33.guest + , subq_33.host + , subq_33.booking__listing + , subq_33.booking__guest + , subq_33.booking__host + , subq_33.is_instant + , subq_33.booking__is_instant + , subq_33.bookings + , subq_33.instant_bookings + , subq_33.booking_value + , subq_33.max_booking_value + , subq_33.min_booking_value + , subq_33.bookers + , subq_33.average_booking_value + , subq_33.referred_bookings + , subq_33.median_booking_value + , subq_33.booking_value_p99 + , subq_33.discrete_booking_value_p99 + , subq_33.approximate_continuous_booking_value_p99 + , subq_33.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_24 - ) subq_25 - ) subq_26 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.ds__day AS metric_time__day + , subq_32.ds__week AS metric_time__week + , subq_32.ds__month AS metric_time__month + , subq_32.ds__quarter AS metric_time__quarter + , subq_32.ds__year AS metric_time__year + , subq_32.ds__extract_year AS metric_time__extract_year + , subq_32.ds__extract_quarter AS metric_time__extract_quarter + , subq_32.ds__extract_month AS metric_time__extract_month + , subq_32.ds__extract_day AS metric_time__extract_day + , subq_32.ds__extract_dow AS metric_time__extract_dow + , subq_32.ds__extract_doy AS metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 + 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_32 + ) subq_33 + WHERE booking__is_instant + ) subq_34 + ) subq_35 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_36 + ) subq_37 + ) subq_38 + ) subq_39 + ) subq_40 +) subq_41 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0_optimized.sql index a73bfea928..60a09b752b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_54.average_booking_value) AS average_booking_value + , MAX(subq_67.bookings) AS bookings + , MAX(subq_75.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_45.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_45.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_43 + WHERE booking__is_instant + ) subq_45 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_45.listing = listings_latest_src_28000.listing_id + ) subq_50 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_54 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_58.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_58.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_56 + WHERE booking__is_instant + ) subq_58 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_58.listing = listings_latest_src_28000.listing_id + ) subq_63 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_67 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_69 + WHERE booking__is_instant + ) subq_71 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_75 + ) subq_76 +) subq_77 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0.sql index 4569d672d5..c4c3c5c749 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_18.average_booking_value) AS average_booking_value + , MAX(subq_31.bookings) AS bookings + , MAX(subq_39.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_17.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_16.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_15.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_14.booking__is_instant + , subq_14.listing__is_lux_latest + , subq_14.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_13.booking__is_instant + , subq_13.listing__is_lux_latest + , subq_13.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.is_lux_latest AS listing__is_lux_latest + , subq_9.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_8.listing + , subq_8.booking__is_instant + , subq_8.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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__day + , 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 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_11.listing + , subq_11.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_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.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ 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_3 - ) subq_4 - ) subq_5 + ) subq_10 + ) subq_11 + ) subq_12 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_15 + ) subq_16 + ) subq_17 + ) subq_18 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_30.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_29.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_28.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_27.booking__is_instant + , subq_27.listing__is_lux_latest + , subq_27.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_22.listing AS listing + , subq_22.booking__is_instant AS booking__is_instant + , subq_25.is_lux_latest AS listing__is_lux_latest + , subq_22.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_21.listing + , subq_21.booking__is_instant + , subq_21.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_20.ds_partitioned__week + , subq_20.ds_partitioned__month + , subq_20.ds_partitioned__quarter + , subq_20.ds_partitioned__year + , subq_20.ds_partitioned__extract_year + , subq_20.ds_partitioned__extract_quarter + , subq_20.ds_partitioned__extract_month + , subq_20.ds_partitioned__extract_day + , subq_20.ds_partitioned__extract_dow + , subq_20.ds_partitioned__extract_doy + , subq_20.paid_at__day + , subq_20.paid_at__week + , subq_20.paid_at__month + , subq_20.paid_at__quarter + , subq_20.paid_at__year + , subq_20.paid_at__extract_year + , subq_20.paid_at__extract_quarter + , subq_20.paid_at__extract_month + , subq_20.paid_at__extract_day + , subq_20.paid_at__extract_dow + , subq_20.paid_at__extract_doy + , subq_20.booking__ds__day + , subq_20.booking__ds__week + , subq_20.booking__ds__month + , subq_20.booking__ds__quarter + , subq_20.booking__ds__year + , subq_20.booking__ds__extract_year + , subq_20.booking__ds__extract_quarter + , subq_20.booking__ds__extract_month + , subq_20.booking__ds__extract_day + , subq_20.booking__ds__extract_dow + , subq_20.booking__ds__extract_doy + , subq_20.booking__ds_partitioned__day + , subq_20.booking__ds_partitioned__week + , subq_20.booking__ds_partitioned__month + , subq_20.booking__ds_partitioned__quarter + , subq_20.booking__ds_partitioned__year + , subq_20.booking__ds_partitioned__extract_year + , subq_20.booking__ds_partitioned__extract_quarter + , subq_20.booking__ds_partitioned__extract_month + , subq_20.booking__ds_partitioned__extract_day + , subq_20.booking__ds_partitioned__extract_dow + , subq_20.booking__ds_partitioned__extract_doy + , subq_20.booking__paid_at__day + , subq_20.booking__paid_at__week + , subq_20.booking__paid_at__month + , subq_20.booking__paid_at__quarter + , subq_20.booking__paid_at__year + , subq_20.booking__paid_at__extract_year + , subq_20.booking__paid_at__extract_quarter + , subq_20.booking__paid_at__extract_month + , subq_20.booking__paid_at__extract_day + , subq_20.booking__paid_at__extract_dow + , subq_20.booking__paid_at__extract_doy + , subq_20.metric_time__day + , subq_20.metric_time__week + , subq_20.metric_time__month + , subq_20.metric_time__quarter + , subq_20.metric_time__year + , subq_20.metric_time__extract_year + , subq_20.metric_time__extract_quarter + , subq_20.metric_time__extract_month + , subq_20.metric_time__extract_day + , subq_20.metric_time__extract_dow + , subq_20.metric_time__extract_doy + , subq_20.listing + , subq_20.guest + , subq_20.host + , subq_20.booking__listing + , subq_20.booking__guest + , subq_20.booking__host + , subq_20.is_instant + , subq_20.booking__is_instant + , subq_20.bookings + , subq_20.instant_bookings + , subq_20.booking_value + , subq_20.max_booking_value + , subq_20.min_booking_value + , subq_20.bookers + , subq_20.average_booking_value + , subq_20.referred_bookings + , subq_20.median_booking_value + , subq_20.booking_value_p99 + , subq_20.discrete_booking_value_p99 + , subq_20.approximate_continuous_booking_value_p99 + , subq_20.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_12 - ) subq_13 - ) subq_14 + 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.ds__day AS metric_time__day + , subq_19.ds__week AS metric_time__week + , subq_19.ds__month AS metric_time__month + , subq_19.ds__quarter AS metric_time__quarter + , subq_19.ds__year AS metric_time__year + , subq_19.ds__extract_year AS metric_time__extract_year + , subq_19.ds__extract_quarter AS metric_time__extract_quarter + , subq_19.ds__extract_month AS metric_time__extract_month + , subq_19.ds__extract_day AS metric_time__extract_day + , subq_19.ds__extract_dow AS metric_time__extract_dow + , subq_19.ds__extract_doy AS metric_time__extract_doy + , 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.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 ( + -- 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_19 + ) subq_20 + WHERE booking__is_instant + ) subq_21 + ) subq_22 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_24.listing + , subq_24.is_lux_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_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.created_at__day + , subq_23.created_at__week + , subq_23.created_at__month + , subq_23.created_at__quarter + , subq_23.created_at__year + , subq_23.created_at__extract_year + , subq_23.created_at__extract_quarter + , subq_23.created_at__extract_month + , subq_23.created_at__extract_day + , subq_23.created_at__extract_dow + , subq_23.created_at__extract_doy + , subq_23.listing__ds__day + , subq_23.listing__ds__week + , subq_23.listing__ds__month + , subq_23.listing__ds__quarter + , subq_23.listing__ds__year + , subq_23.listing__ds__extract_year + , subq_23.listing__ds__extract_quarter + , subq_23.listing__ds__extract_month + , subq_23.listing__ds__extract_day + , subq_23.listing__ds__extract_dow + , subq_23.listing__ds__extract_doy + , subq_23.listing__created_at__day + , subq_23.listing__created_at__week + , subq_23.listing__created_at__month + , subq_23.listing__created_at__quarter + , subq_23.listing__created_at__year + , subq_23.listing__created_at__extract_year + , subq_23.listing__created_at__extract_quarter + , subq_23.listing__created_at__extract_month + , subq_23.listing__created_at__extract_day + , subq_23.listing__created_at__extract_dow + , subq_23.listing__created_at__extract_doy + , subq_23.ds__day AS metric_time__day + , subq_23.ds__week AS metric_time__week + , subq_23.ds__month AS metric_time__month + , subq_23.ds__quarter AS metric_time__quarter + , subq_23.ds__year AS metric_time__year + , subq_23.ds__extract_year AS metric_time__extract_year + , subq_23.ds__extract_quarter AS metric_time__extract_quarter + , subq_23.ds__extract_month AS metric_time__extract_month + , subq_23.ds__extract_day AS metric_time__extract_day + , subq_23.ds__extract_dow AS metric_time__extract_dow + , subq_23.ds__extract_doy AS metric_time__extract_doy + , subq_23.listing + , subq_23.user + , subq_23.listing__user + , subq_23.country_latest + , subq_23.is_lux_latest + , subq_23.capacity_latest + , subq_23.listing__country_latest + , subq_23.listing__is_lux_latest + , subq_23.listing__capacity_latest + , subq_23.listings + , subq_23.largest_listing + , subq_23.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ 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_23 + ) subq_24 + ) subq_25 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_22.listing = subq_25.listing + ) subq_26 + ) subq_27 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_28 + ) subq_29 + ) subq_30 + ) subq_31 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_38.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_37.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_36.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_35.booking__is_instant + , subq_35.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_34.booking__is_instant + , subq_34.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_33.ds__day + , subq_33.ds__week + , subq_33.ds__month + , subq_33.ds__quarter + , subq_33.ds__year + , subq_33.ds__extract_year + , subq_33.ds__extract_quarter + , subq_33.ds__extract_month + , subq_33.ds__extract_day + , subq_33.ds__extract_dow + , subq_33.ds__extract_doy + , subq_33.ds_partitioned__day + , subq_33.ds_partitioned__week + , subq_33.ds_partitioned__month + , subq_33.ds_partitioned__quarter + , subq_33.ds_partitioned__year + , subq_33.ds_partitioned__extract_year + , subq_33.ds_partitioned__extract_quarter + , subq_33.ds_partitioned__extract_month + , subq_33.ds_partitioned__extract_day + , subq_33.ds_partitioned__extract_dow + , subq_33.ds_partitioned__extract_doy + , subq_33.paid_at__day + , subq_33.paid_at__week + , subq_33.paid_at__month + , subq_33.paid_at__quarter + , subq_33.paid_at__year + , subq_33.paid_at__extract_year + , subq_33.paid_at__extract_quarter + , subq_33.paid_at__extract_month + , subq_33.paid_at__extract_day + , subq_33.paid_at__extract_dow + , subq_33.paid_at__extract_doy + , subq_33.booking__ds__day + , subq_33.booking__ds__week + , subq_33.booking__ds__month + , subq_33.booking__ds__quarter + , subq_33.booking__ds__year + , subq_33.booking__ds__extract_year + , subq_33.booking__ds__extract_quarter + , subq_33.booking__ds__extract_month + , subq_33.booking__ds__extract_day + , subq_33.booking__ds__extract_dow + , subq_33.booking__ds__extract_doy + , subq_33.booking__ds_partitioned__day + , subq_33.booking__ds_partitioned__week + , subq_33.booking__ds_partitioned__month + , subq_33.booking__ds_partitioned__quarter + , subq_33.booking__ds_partitioned__year + , subq_33.booking__ds_partitioned__extract_year + , subq_33.booking__ds_partitioned__extract_quarter + , subq_33.booking__ds_partitioned__extract_month + , subq_33.booking__ds_partitioned__extract_day + , subq_33.booking__ds_partitioned__extract_dow + , subq_33.booking__ds_partitioned__extract_doy + , subq_33.booking__paid_at__day + , subq_33.booking__paid_at__week + , subq_33.booking__paid_at__month + , subq_33.booking__paid_at__quarter + , subq_33.booking__paid_at__year + , subq_33.booking__paid_at__extract_year + , subq_33.booking__paid_at__extract_quarter + , subq_33.booking__paid_at__extract_month + , subq_33.booking__paid_at__extract_day + , subq_33.booking__paid_at__extract_dow + , subq_33.booking__paid_at__extract_doy + , subq_33.metric_time__day + , subq_33.metric_time__week + , subq_33.metric_time__month + , subq_33.metric_time__quarter + , subq_33.metric_time__year + , subq_33.metric_time__extract_year + , subq_33.metric_time__extract_quarter + , subq_33.metric_time__extract_month + , subq_33.metric_time__extract_day + , subq_33.metric_time__extract_dow + , subq_33.metric_time__extract_doy + , subq_33.listing + , subq_33.guest + , subq_33.host + , subq_33.booking__listing + , subq_33.booking__guest + , subq_33.booking__host + , subq_33.is_instant + , subq_33.booking__is_instant + , subq_33.bookings + , subq_33.instant_bookings + , subq_33.booking_value + , subq_33.max_booking_value + , subq_33.min_booking_value + , subq_33.bookers + , subq_33.average_booking_value + , subq_33.referred_bookings + , subq_33.median_booking_value + , subq_33.booking_value_p99 + , subq_33.discrete_booking_value_p99 + , subq_33.approximate_continuous_booking_value_p99 + , subq_33.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_24 - ) subq_25 - ) subq_26 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.ds__day AS metric_time__day + , subq_32.ds__week AS metric_time__week + , subq_32.ds__month AS metric_time__month + , subq_32.ds__quarter AS metric_time__quarter + , subq_32.ds__year AS metric_time__year + , subq_32.ds__extract_year AS metric_time__extract_year + , subq_32.ds__extract_quarter AS metric_time__extract_quarter + , subq_32.ds__extract_month AS metric_time__extract_month + , subq_32.ds__extract_day AS metric_time__extract_day + , subq_32.ds__extract_dow AS metric_time__extract_dow + , subq_32.ds__extract_doy AS metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 + 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_32 + ) subq_33 + WHERE booking__is_instant + ) subq_34 + ) subq_35 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_36 + ) subq_37 + ) subq_38 + ) subq_39 + ) subq_40 +) subq_41 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0_optimized.sql index a73bfea928..60a09b752b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_54.average_booking_value) AS average_booking_value + , MAX(subq_67.bookings) AS bookings + , MAX(subq_75.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_45.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_45.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_43 + WHERE booking__is_instant + ) subq_45 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_45.listing = listings_latest_src_28000.listing_id + ) subq_50 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_54 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_58.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_58.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_56 + WHERE booking__is_instant + ) subq_58 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_58.listing = listings_latest_src_28000.listing_id + ) subq_63 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_67 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_69 + WHERE booking__is_instant + ) subq_71 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_75 + ) subq_76 +) subq_77 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0.sql index 4569d672d5..c4c3c5c749 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_18.average_booking_value) AS average_booking_value + , MAX(subq_31.bookings) AS bookings + , MAX(subq_39.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_17.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_16.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_15.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_14.booking__is_instant + , subq_14.listing__is_lux_latest + , subq_14.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_13.booking__is_instant + , subq_13.listing__is_lux_latest + , subq_13.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.is_lux_latest AS listing__is_lux_latest + , subq_9.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_8.listing + , subq_8.booking__is_instant + , subq_8.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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__day + , 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 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_11.listing + , subq_11.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_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.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ 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_3 - ) subq_4 - ) subq_5 + ) subq_10 + ) subq_11 + ) subq_12 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_15 + ) subq_16 + ) subq_17 + ) subq_18 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_30.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_29.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_28.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_27.booking__is_instant + , subq_27.listing__is_lux_latest + , subq_27.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_22.listing AS listing + , subq_22.booking__is_instant AS booking__is_instant + , subq_25.is_lux_latest AS listing__is_lux_latest + , subq_22.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_21.listing + , subq_21.booking__is_instant + , subq_21.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_20.ds_partitioned__week + , subq_20.ds_partitioned__month + , subq_20.ds_partitioned__quarter + , subq_20.ds_partitioned__year + , subq_20.ds_partitioned__extract_year + , subq_20.ds_partitioned__extract_quarter + , subq_20.ds_partitioned__extract_month + , subq_20.ds_partitioned__extract_day + , subq_20.ds_partitioned__extract_dow + , subq_20.ds_partitioned__extract_doy + , subq_20.paid_at__day + , subq_20.paid_at__week + , subq_20.paid_at__month + , subq_20.paid_at__quarter + , subq_20.paid_at__year + , subq_20.paid_at__extract_year + , subq_20.paid_at__extract_quarter + , subq_20.paid_at__extract_month + , subq_20.paid_at__extract_day + , subq_20.paid_at__extract_dow + , subq_20.paid_at__extract_doy + , subq_20.booking__ds__day + , subq_20.booking__ds__week + , subq_20.booking__ds__month + , subq_20.booking__ds__quarter + , subq_20.booking__ds__year + , subq_20.booking__ds__extract_year + , subq_20.booking__ds__extract_quarter + , subq_20.booking__ds__extract_month + , subq_20.booking__ds__extract_day + , subq_20.booking__ds__extract_dow + , subq_20.booking__ds__extract_doy + , subq_20.booking__ds_partitioned__day + , subq_20.booking__ds_partitioned__week + , subq_20.booking__ds_partitioned__month + , subq_20.booking__ds_partitioned__quarter + , subq_20.booking__ds_partitioned__year + , subq_20.booking__ds_partitioned__extract_year + , subq_20.booking__ds_partitioned__extract_quarter + , subq_20.booking__ds_partitioned__extract_month + , subq_20.booking__ds_partitioned__extract_day + , subq_20.booking__ds_partitioned__extract_dow + , subq_20.booking__ds_partitioned__extract_doy + , subq_20.booking__paid_at__day + , subq_20.booking__paid_at__week + , subq_20.booking__paid_at__month + , subq_20.booking__paid_at__quarter + , subq_20.booking__paid_at__year + , subq_20.booking__paid_at__extract_year + , subq_20.booking__paid_at__extract_quarter + , subq_20.booking__paid_at__extract_month + , subq_20.booking__paid_at__extract_day + , subq_20.booking__paid_at__extract_dow + , subq_20.booking__paid_at__extract_doy + , subq_20.metric_time__day + , subq_20.metric_time__week + , subq_20.metric_time__month + , subq_20.metric_time__quarter + , subq_20.metric_time__year + , subq_20.metric_time__extract_year + , subq_20.metric_time__extract_quarter + , subq_20.metric_time__extract_month + , subq_20.metric_time__extract_day + , subq_20.metric_time__extract_dow + , subq_20.metric_time__extract_doy + , subq_20.listing + , subq_20.guest + , subq_20.host + , subq_20.booking__listing + , subq_20.booking__guest + , subq_20.booking__host + , subq_20.is_instant + , subq_20.booking__is_instant + , subq_20.bookings + , subq_20.instant_bookings + , subq_20.booking_value + , subq_20.max_booking_value + , subq_20.min_booking_value + , subq_20.bookers + , subq_20.average_booking_value + , subq_20.referred_bookings + , subq_20.median_booking_value + , subq_20.booking_value_p99 + , subq_20.discrete_booking_value_p99 + , subq_20.approximate_continuous_booking_value_p99 + , subq_20.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_12 - ) subq_13 - ) subq_14 + 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.ds__day AS metric_time__day + , subq_19.ds__week AS metric_time__week + , subq_19.ds__month AS metric_time__month + , subq_19.ds__quarter AS metric_time__quarter + , subq_19.ds__year AS metric_time__year + , subq_19.ds__extract_year AS metric_time__extract_year + , subq_19.ds__extract_quarter AS metric_time__extract_quarter + , subq_19.ds__extract_month AS metric_time__extract_month + , subq_19.ds__extract_day AS metric_time__extract_day + , subq_19.ds__extract_dow AS metric_time__extract_dow + , subq_19.ds__extract_doy AS metric_time__extract_doy + , 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.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 ( + -- 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_19 + ) subq_20 + WHERE booking__is_instant + ) subq_21 + ) subq_22 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_24.listing + , subq_24.is_lux_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_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.created_at__day + , subq_23.created_at__week + , subq_23.created_at__month + , subq_23.created_at__quarter + , subq_23.created_at__year + , subq_23.created_at__extract_year + , subq_23.created_at__extract_quarter + , subq_23.created_at__extract_month + , subq_23.created_at__extract_day + , subq_23.created_at__extract_dow + , subq_23.created_at__extract_doy + , subq_23.listing__ds__day + , subq_23.listing__ds__week + , subq_23.listing__ds__month + , subq_23.listing__ds__quarter + , subq_23.listing__ds__year + , subq_23.listing__ds__extract_year + , subq_23.listing__ds__extract_quarter + , subq_23.listing__ds__extract_month + , subq_23.listing__ds__extract_day + , subq_23.listing__ds__extract_dow + , subq_23.listing__ds__extract_doy + , subq_23.listing__created_at__day + , subq_23.listing__created_at__week + , subq_23.listing__created_at__month + , subq_23.listing__created_at__quarter + , subq_23.listing__created_at__year + , subq_23.listing__created_at__extract_year + , subq_23.listing__created_at__extract_quarter + , subq_23.listing__created_at__extract_month + , subq_23.listing__created_at__extract_day + , subq_23.listing__created_at__extract_dow + , subq_23.listing__created_at__extract_doy + , subq_23.ds__day AS metric_time__day + , subq_23.ds__week AS metric_time__week + , subq_23.ds__month AS metric_time__month + , subq_23.ds__quarter AS metric_time__quarter + , subq_23.ds__year AS metric_time__year + , subq_23.ds__extract_year AS metric_time__extract_year + , subq_23.ds__extract_quarter AS metric_time__extract_quarter + , subq_23.ds__extract_month AS metric_time__extract_month + , subq_23.ds__extract_day AS metric_time__extract_day + , subq_23.ds__extract_dow AS metric_time__extract_dow + , subq_23.ds__extract_doy AS metric_time__extract_doy + , subq_23.listing + , subq_23.user + , subq_23.listing__user + , subq_23.country_latest + , subq_23.is_lux_latest + , subq_23.capacity_latest + , subq_23.listing__country_latest + , subq_23.listing__is_lux_latest + , subq_23.listing__capacity_latest + , subq_23.listings + , subq_23.largest_listing + , subq_23.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ 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_23 + ) subq_24 + ) subq_25 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_22.listing = subq_25.listing + ) subq_26 + ) subq_27 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_28 + ) subq_29 + ) subq_30 + ) subq_31 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_38.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_37.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_36.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_35.booking__is_instant + , subq_35.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_34.booking__is_instant + , subq_34.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_33.ds__day + , subq_33.ds__week + , subq_33.ds__month + , subq_33.ds__quarter + , subq_33.ds__year + , subq_33.ds__extract_year + , subq_33.ds__extract_quarter + , subq_33.ds__extract_month + , subq_33.ds__extract_day + , subq_33.ds__extract_dow + , subq_33.ds__extract_doy + , subq_33.ds_partitioned__day + , subq_33.ds_partitioned__week + , subq_33.ds_partitioned__month + , subq_33.ds_partitioned__quarter + , subq_33.ds_partitioned__year + , subq_33.ds_partitioned__extract_year + , subq_33.ds_partitioned__extract_quarter + , subq_33.ds_partitioned__extract_month + , subq_33.ds_partitioned__extract_day + , subq_33.ds_partitioned__extract_dow + , subq_33.ds_partitioned__extract_doy + , subq_33.paid_at__day + , subq_33.paid_at__week + , subq_33.paid_at__month + , subq_33.paid_at__quarter + , subq_33.paid_at__year + , subq_33.paid_at__extract_year + , subq_33.paid_at__extract_quarter + , subq_33.paid_at__extract_month + , subq_33.paid_at__extract_day + , subq_33.paid_at__extract_dow + , subq_33.paid_at__extract_doy + , subq_33.booking__ds__day + , subq_33.booking__ds__week + , subq_33.booking__ds__month + , subq_33.booking__ds__quarter + , subq_33.booking__ds__year + , subq_33.booking__ds__extract_year + , subq_33.booking__ds__extract_quarter + , subq_33.booking__ds__extract_month + , subq_33.booking__ds__extract_day + , subq_33.booking__ds__extract_dow + , subq_33.booking__ds__extract_doy + , subq_33.booking__ds_partitioned__day + , subq_33.booking__ds_partitioned__week + , subq_33.booking__ds_partitioned__month + , subq_33.booking__ds_partitioned__quarter + , subq_33.booking__ds_partitioned__year + , subq_33.booking__ds_partitioned__extract_year + , subq_33.booking__ds_partitioned__extract_quarter + , subq_33.booking__ds_partitioned__extract_month + , subq_33.booking__ds_partitioned__extract_day + , subq_33.booking__ds_partitioned__extract_dow + , subq_33.booking__ds_partitioned__extract_doy + , subq_33.booking__paid_at__day + , subq_33.booking__paid_at__week + , subq_33.booking__paid_at__month + , subq_33.booking__paid_at__quarter + , subq_33.booking__paid_at__year + , subq_33.booking__paid_at__extract_year + , subq_33.booking__paid_at__extract_quarter + , subq_33.booking__paid_at__extract_month + , subq_33.booking__paid_at__extract_day + , subq_33.booking__paid_at__extract_dow + , subq_33.booking__paid_at__extract_doy + , subq_33.metric_time__day + , subq_33.metric_time__week + , subq_33.metric_time__month + , subq_33.metric_time__quarter + , subq_33.metric_time__year + , subq_33.metric_time__extract_year + , subq_33.metric_time__extract_quarter + , subq_33.metric_time__extract_month + , subq_33.metric_time__extract_day + , subq_33.metric_time__extract_dow + , subq_33.metric_time__extract_doy + , subq_33.listing + , subq_33.guest + , subq_33.host + , subq_33.booking__listing + , subq_33.booking__guest + , subq_33.booking__host + , subq_33.is_instant + , subq_33.booking__is_instant + , subq_33.bookings + , subq_33.instant_bookings + , subq_33.booking_value + , subq_33.max_booking_value + , subq_33.min_booking_value + , subq_33.bookers + , subq_33.average_booking_value + , subq_33.referred_bookings + , subq_33.median_booking_value + , subq_33.booking_value_p99 + , subq_33.discrete_booking_value_p99 + , subq_33.approximate_continuous_booking_value_p99 + , subq_33.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_24 - ) subq_25 - ) subq_26 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.ds__day AS metric_time__day + , subq_32.ds__week AS metric_time__week + , subq_32.ds__month AS metric_time__month + , subq_32.ds__quarter AS metric_time__quarter + , subq_32.ds__year AS metric_time__year + , subq_32.ds__extract_year AS metric_time__extract_year + , subq_32.ds__extract_quarter AS metric_time__extract_quarter + , subq_32.ds__extract_month AS metric_time__extract_month + , subq_32.ds__extract_day AS metric_time__extract_day + , subq_32.ds__extract_dow AS metric_time__extract_dow + , subq_32.ds__extract_doy AS metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 + 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_32 + ) subq_33 + WHERE booking__is_instant + ) subq_34 + ) subq_35 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_36 + ) subq_37 + ) subq_38 + ) subq_39 + ) subq_40 +) subq_41 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0_optimized.sql index a73bfea928..60a09b752b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_54.average_booking_value) AS average_booking_value + , MAX(subq_67.bookings) AS bookings + , MAX(subq_75.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_45.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_45.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_43 + WHERE booking__is_instant + ) subq_45 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_45.listing = listings_latest_src_28000.listing_id + ) subq_50 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_54 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_58.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_58.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_56 + WHERE booking__is_instant + ) subq_58 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_58.listing = listings_latest_src_28000.listing_id + ) subq_63 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_67 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_69 + WHERE booking__is_instant + ) subq_71 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_75 + ) subq_76 +) subq_77 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0.sql index 5db13f9c09..c6a4999e10 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_18.average_booking_value) AS average_booking_value + , MAX(subq_31.bookings) AS bookings + , MAX(subq_39.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_17.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_16.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_15.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_14.booking__is_instant + , subq_14.listing__is_lux_latest + , subq_14.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_13.booking__is_instant + , subq_13.listing__is_lux_latest + , subq_13.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.is_lux_latest AS listing__is_lux_latest + , subq_9.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_8.listing + , subq_8.booking__is_instant + , subq_8.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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__day + , 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 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_11.listing + , subq_11.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_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.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ 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_3 - ) subq_4 - ) subq_5 + ) subq_10 + ) subq_11 + ) subq_12 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_15 + ) subq_16 + ) subq_17 + ) subq_18 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_30.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_29.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_28.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_27.booking__is_instant + , subq_27.listing__is_lux_latest + , subq_27.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_22.listing AS listing + , subq_22.booking__is_instant AS booking__is_instant + , subq_25.is_lux_latest AS listing__is_lux_latest + , subq_22.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_21.listing + , subq_21.booking__is_instant + , subq_21.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_20.ds_partitioned__week + , subq_20.ds_partitioned__month + , subq_20.ds_partitioned__quarter + , subq_20.ds_partitioned__year + , subq_20.ds_partitioned__extract_year + , subq_20.ds_partitioned__extract_quarter + , subq_20.ds_partitioned__extract_month + , subq_20.ds_partitioned__extract_day + , subq_20.ds_partitioned__extract_dow + , subq_20.ds_partitioned__extract_doy + , subq_20.paid_at__day + , subq_20.paid_at__week + , subq_20.paid_at__month + , subq_20.paid_at__quarter + , subq_20.paid_at__year + , subq_20.paid_at__extract_year + , subq_20.paid_at__extract_quarter + , subq_20.paid_at__extract_month + , subq_20.paid_at__extract_day + , subq_20.paid_at__extract_dow + , subq_20.paid_at__extract_doy + , subq_20.booking__ds__day + , subq_20.booking__ds__week + , subq_20.booking__ds__month + , subq_20.booking__ds__quarter + , subq_20.booking__ds__year + , subq_20.booking__ds__extract_year + , subq_20.booking__ds__extract_quarter + , subq_20.booking__ds__extract_month + , subq_20.booking__ds__extract_day + , subq_20.booking__ds__extract_dow + , subq_20.booking__ds__extract_doy + , subq_20.booking__ds_partitioned__day + , subq_20.booking__ds_partitioned__week + , subq_20.booking__ds_partitioned__month + , subq_20.booking__ds_partitioned__quarter + , subq_20.booking__ds_partitioned__year + , subq_20.booking__ds_partitioned__extract_year + , subq_20.booking__ds_partitioned__extract_quarter + , subq_20.booking__ds_partitioned__extract_month + , subq_20.booking__ds_partitioned__extract_day + , subq_20.booking__ds_partitioned__extract_dow + , subq_20.booking__ds_partitioned__extract_doy + , subq_20.booking__paid_at__day + , subq_20.booking__paid_at__week + , subq_20.booking__paid_at__month + , subq_20.booking__paid_at__quarter + , subq_20.booking__paid_at__year + , subq_20.booking__paid_at__extract_year + , subq_20.booking__paid_at__extract_quarter + , subq_20.booking__paid_at__extract_month + , subq_20.booking__paid_at__extract_day + , subq_20.booking__paid_at__extract_dow + , subq_20.booking__paid_at__extract_doy + , subq_20.metric_time__day + , subq_20.metric_time__week + , subq_20.metric_time__month + , subq_20.metric_time__quarter + , subq_20.metric_time__year + , subq_20.metric_time__extract_year + , subq_20.metric_time__extract_quarter + , subq_20.metric_time__extract_month + , subq_20.metric_time__extract_day + , subq_20.metric_time__extract_dow + , subq_20.metric_time__extract_doy + , subq_20.listing + , subq_20.guest + , subq_20.host + , subq_20.booking__listing + , subq_20.booking__guest + , subq_20.booking__host + , subq_20.is_instant + , subq_20.booking__is_instant + , subq_20.bookings + , subq_20.instant_bookings + , subq_20.booking_value + , subq_20.max_booking_value + , subq_20.min_booking_value + , subq_20.bookers + , subq_20.average_booking_value + , subq_20.referred_bookings + , subq_20.median_booking_value + , subq_20.booking_value_p99 + , subq_20.discrete_booking_value_p99 + , subq_20.approximate_continuous_booking_value_p99 + , subq_20.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_12 - ) subq_13 - ) subq_14 + 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.ds__day AS metric_time__day + , subq_19.ds__week AS metric_time__week + , subq_19.ds__month AS metric_time__month + , subq_19.ds__quarter AS metric_time__quarter + , subq_19.ds__year AS metric_time__year + , subq_19.ds__extract_year AS metric_time__extract_year + , subq_19.ds__extract_quarter AS metric_time__extract_quarter + , subq_19.ds__extract_month AS metric_time__extract_month + , subq_19.ds__extract_day AS metric_time__extract_day + , subq_19.ds__extract_dow AS metric_time__extract_dow + , subq_19.ds__extract_doy AS metric_time__extract_doy + , 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.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 ( + -- 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_19 + ) subq_20 + WHERE booking__is_instant + ) subq_21 + ) subq_22 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_24.listing + , subq_24.is_lux_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_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.created_at__day + , subq_23.created_at__week + , subq_23.created_at__month + , subq_23.created_at__quarter + , subq_23.created_at__year + , subq_23.created_at__extract_year + , subq_23.created_at__extract_quarter + , subq_23.created_at__extract_month + , subq_23.created_at__extract_day + , subq_23.created_at__extract_dow + , subq_23.created_at__extract_doy + , subq_23.listing__ds__day + , subq_23.listing__ds__week + , subq_23.listing__ds__month + , subq_23.listing__ds__quarter + , subq_23.listing__ds__year + , subq_23.listing__ds__extract_year + , subq_23.listing__ds__extract_quarter + , subq_23.listing__ds__extract_month + , subq_23.listing__ds__extract_day + , subq_23.listing__ds__extract_dow + , subq_23.listing__ds__extract_doy + , subq_23.listing__created_at__day + , subq_23.listing__created_at__week + , subq_23.listing__created_at__month + , subq_23.listing__created_at__quarter + , subq_23.listing__created_at__year + , subq_23.listing__created_at__extract_year + , subq_23.listing__created_at__extract_quarter + , subq_23.listing__created_at__extract_month + , subq_23.listing__created_at__extract_day + , subq_23.listing__created_at__extract_dow + , subq_23.listing__created_at__extract_doy + , subq_23.ds__day AS metric_time__day + , subq_23.ds__week AS metric_time__week + , subq_23.ds__month AS metric_time__month + , subq_23.ds__quarter AS metric_time__quarter + , subq_23.ds__year AS metric_time__year + , subq_23.ds__extract_year AS metric_time__extract_year + , subq_23.ds__extract_quarter AS metric_time__extract_quarter + , subq_23.ds__extract_month AS metric_time__extract_month + , subq_23.ds__extract_day AS metric_time__extract_day + , subq_23.ds__extract_dow AS metric_time__extract_dow + , subq_23.ds__extract_doy AS metric_time__extract_doy + , subq_23.listing + , subq_23.user + , subq_23.listing__user + , subq_23.country_latest + , subq_23.is_lux_latest + , subq_23.capacity_latest + , subq_23.listing__country_latest + , subq_23.listing__is_lux_latest + , subq_23.listing__capacity_latest + , subq_23.listings + , subq_23.largest_listing + , subq_23.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ 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_23 + ) subq_24 + ) subq_25 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_22.listing = subq_25.listing + ) subq_26 + ) subq_27 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_28 + ) subq_29 + ) subq_30 + ) subq_31 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_38.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_37.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_36.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_35.booking__is_instant + , subq_35.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_34.booking__is_instant + , subq_34.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_33.ds__day + , subq_33.ds__week + , subq_33.ds__month + , subq_33.ds__quarter + , subq_33.ds__year + , subq_33.ds__extract_year + , subq_33.ds__extract_quarter + , subq_33.ds__extract_month + , subq_33.ds__extract_day + , subq_33.ds__extract_dow + , subq_33.ds__extract_doy + , subq_33.ds_partitioned__day + , subq_33.ds_partitioned__week + , subq_33.ds_partitioned__month + , subq_33.ds_partitioned__quarter + , subq_33.ds_partitioned__year + , subq_33.ds_partitioned__extract_year + , subq_33.ds_partitioned__extract_quarter + , subq_33.ds_partitioned__extract_month + , subq_33.ds_partitioned__extract_day + , subq_33.ds_partitioned__extract_dow + , subq_33.ds_partitioned__extract_doy + , subq_33.paid_at__day + , subq_33.paid_at__week + , subq_33.paid_at__month + , subq_33.paid_at__quarter + , subq_33.paid_at__year + , subq_33.paid_at__extract_year + , subq_33.paid_at__extract_quarter + , subq_33.paid_at__extract_month + , subq_33.paid_at__extract_day + , subq_33.paid_at__extract_dow + , subq_33.paid_at__extract_doy + , subq_33.booking__ds__day + , subq_33.booking__ds__week + , subq_33.booking__ds__month + , subq_33.booking__ds__quarter + , subq_33.booking__ds__year + , subq_33.booking__ds__extract_year + , subq_33.booking__ds__extract_quarter + , subq_33.booking__ds__extract_month + , subq_33.booking__ds__extract_day + , subq_33.booking__ds__extract_dow + , subq_33.booking__ds__extract_doy + , subq_33.booking__ds_partitioned__day + , subq_33.booking__ds_partitioned__week + , subq_33.booking__ds_partitioned__month + , subq_33.booking__ds_partitioned__quarter + , subq_33.booking__ds_partitioned__year + , subq_33.booking__ds_partitioned__extract_year + , subq_33.booking__ds_partitioned__extract_quarter + , subq_33.booking__ds_partitioned__extract_month + , subq_33.booking__ds_partitioned__extract_day + , subq_33.booking__ds_partitioned__extract_dow + , subq_33.booking__ds_partitioned__extract_doy + , subq_33.booking__paid_at__day + , subq_33.booking__paid_at__week + , subq_33.booking__paid_at__month + , subq_33.booking__paid_at__quarter + , subq_33.booking__paid_at__year + , subq_33.booking__paid_at__extract_year + , subq_33.booking__paid_at__extract_quarter + , subq_33.booking__paid_at__extract_month + , subq_33.booking__paid_at__extract_day + , subq_33.booking__paid_at__extract_dow + , subq_33.booking__paid_at__extract_doy + , subq_33.metric_time__day + , subq_33.metric_time__week + , subq_33.metric_time__month + , subq_33.metric_time__quarter + , subq_33.metric_time__year + , subq_33.metric_time__extract_year + , subq_33.metric_time__extract_quarter + , subq_33.metric_time__extract_month + , subq_33.metric_time__extract_day + , subq_33.metric_time__extract_dow + , subq_33.metric_time__extract_doy + , subq_33.listing + , subq_33.guest + , subq_33.host + , subq_33.booking__listing + , subq_33.booking__guest + , subq_33.booking__host + , subq_33.is_instant + , subq_33.booking__is_instant + , subq_33.bookings + , subq_33.instant_bookings + , subq_33.booking_value + , subq_33.max_booking_value + , subq_33.min_booking_value + , subq_33.bookers + , subq_33.average_booking_value + , subq_33.referred_bookings + , subq_33.median_booking_value + , subq_33.booking_value_p99 + , subq_33.discrete_booking_value_p99 + , subq_33.approximate_continuous_booking_value_p99 + , subq_33.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_24 - ) subq_25 - ) subq_26 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.ds__day AS metric_time__day + , subq_32.ds__week AS metric_time__week + , subq_32.ds__month AS metric_time__month + , subq_32.ds__quarter AS metric_time__quarter + , subq_32.ds__year AS metric_time__year + , subq_32.ds__extract_year AS metric_time__extract_year + , subq_32.ds__extract_quarter AS metric_time__extract_quarter + , subq_32.ds__extract_month AS metric_time__extract_month + , subq_32.ds__extract_day AS metric_time__extract_day + , subq_32.ds__extract_dow AS metric_time__extract_dow + , subq_32.ds__extract_doy AS metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 + 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_32 + ) subq_33 + WHERE booking__is_instant + ) subq_34 + ) subq_35 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_36 + ) subq_37 + ) subq_38 + ) subq_39 + ) subq_40 +) subq_41 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0_optimized.sql index a73bfea928..60a09b752b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_54.average_booking_value) AS average_booking_value + , MAX(subq_67.bookings) AS bookings + , MAX(subq_75.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_45.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_45.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_43 + WHERE booking__is_instant + ) subq_45 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_45.listing = listings_latest_src_28000.listing_id + ) subq_50 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_54 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_58.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_58.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_56 + WHERE booking__is_instant + ) subq_58 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_58.listing = listings_latest_src_28000.listing_id + ) subq_63 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_67 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_69 + WHERE booking__is_instant + ) subq_71 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_75 + ) subq_76 +) subq_77 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0.sql index ed681431ce..dfcc81fb82 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_18.average_booking_value) AS average_booking_value + , MAX(subq_31.bookings) AS bookings + , MAX(subq_39.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_17.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_16.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_15.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_14.booking__is_instant + , subq_14.listing__is_lux_latest + , subq_14.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_13.booking__is_instant + , subq_13.listing__is_lux_latest + , subq_13.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.is_lux_latest AS listing__is_lux_latest + , subq_9.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_8.listing + , subq_8.booking__is_instant + , subq_8.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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__day + , 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 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_11.listing + , subq_11.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_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.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ 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_3 - ) subq_4 - ) subq_5 + ) subq_10 + ) subq_11 + ) subq_12 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_15 + ) subq_16 + ) subq_17 + ) subq_18 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_30.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_29.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_28.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_27.booking__is_instant + , subq_27.listing__is_lux_latest + , subq_27.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_22.listing AS listing + , subq_22.booking__is_instant AS booking__is_instant + , subq_25.is_lux_latest AS listing__is_lux_latest + , subq_22.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_21.listing + , subq_21.booking__is_instant + , subq_21.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_20.ds_partitioned__week + , subq_20.ds_partitioned__month + , subq_20.ds_partitioned__quarter + , subq_20.ds_partitioned__year + , subq_20.ds_partitioned__extract_year + , subq_20.ds_partitioned__extract_quarter + , subq_20.ds_partitioned__extract_month + , subq_20.ds_partitioned__extract_day + , subq_20.ds_partitioned__extract_dow + , subq_20.ds_partitioned__extract_doy + , subq_20.paid_at__day + , subq_20.paid_at__week + , subq_20.paid_at__month + , subq_20.paid_at__quarter + , subq_20.paid_at__year + , subq_20.paid_at__extract_year + , subq_20.paid_at__extract_quarter + , subq_20.paid_at__extract_month + , subq_20.paid_at__extract_day + , subq_20.paid_at__extract_dow + , subq_20.paid_at__extract_doy + , subq_20.booking__ds__day + , subq_20.booking__ds__week + , subq_20.booking__ds__month + , subq_20.booking__ds__quarter + , subq_20.booking__ds__year + , subq_20.booking__ds__extract_year + , subq_20.booking__ds__extract_quarter + , subq_20.booking__ds__extract_month + , subq_20.booking__ds__extract_day + , subq_20.booking__ds__extract_dow + , subq_20.booking__ds__extract_doy + , subq_20.booking__ds_partitioned__day + , subq_20.booking__ds_partitioned__week + , subq_20.booking__ds_partitioned__month + , subq_20.booking__ds_partitioned__quarter + , subq_20.booking__ds_partitioned__year + , subq_20.booking__ds_partitioned__extract_year + , subq_20.booking__ds_partitioned__extract_quarter + , subq_20.booking__ds_partitioned__extract_month + , subq_20.booking__ds_partitioned__extract_day + , subq_20.booking__ds_partitioned__extract_dow + , subq_20.booking__ds_partitioned__extract_doy + , subq_20.booking__paid_at__day + , subq_20.booking__paid_at__week + , subq_20.booking__paid_at__month + , subq_20.booking__paid_at__quarter + , subq_20.booking__paid_at__year + , subq_20.booking__paid_at__extract_year + , subq_20.booking__paid_at__extract_quarter + , subq_20.booking__paid_at__extract_month + , subq_20.booking__paid_at__extract_day + , subq_20.booking__paid_at__extract_dow + , subq_20.booking__paid_at__extract_doy + , subq_20.metric_time__day + , subq_20.metric_time__week + , subq_20.metric_time__month + , subq_20.metric_time__quarter + , subq_20.metric_time__year + , subq_20.metric_time__extract_year + , subq_20.metric_time__extract_quarter + , subq_20.metric_time__extract_month + , subq_20.metric_time__extract_day + , subq_20.metric_time__extract_dow + , subq_20.metric_time__extract_doy + , subq_20.listing + , subq_20.guest + , subq_20.host + , subq_20.booking__listing + , subq_20.booking__guest + , subq_20.booking__host + , subq_20.is_instant + , subq_20.booking__is_instant + , subq_20.bookings + , subq_20.instant_bookings + , subq_20.booking_value + , subq_20.max_booking_value + , subq_20.min_booking_value + , subq_20.bookers + , subq_20.average_booking_value + , subq_20.referred_bookings + , subq_20.median_booking_value + , subq_20.booking_value_p99 + , subq_20.discrete_booking_value_p99 + , subq_20.approximate_continuous_booking_value_p99 + , subq_20.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_12 - ) subq_13 - ) subq_14 + 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.ds__day AS metric_time__day + , subq_19.ds__week AS metric_time__week + , subq_19.ds__month AS metric_time__month + , subq_19.ds__quarter AS metric_time__quarter + , subq_19.ds__year AS metric_time__year + , subq_19.ds__extract_year AS metric_time__extract_year + , subq_19.ds__extract_quarter AS metric_time__extract_quarter + , subq_19.ds__extract_month AS metric_time__extract_month + , subq_19.ds__extract_day AS metric_time__extract_day + , subq_19.ds__extract_dow AS metric_time__extract_dow + , subq_19.ds__extract_doy AS metric_time__extract_doy + , 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.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 ( + -- 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_19 + ) subq_20 + WHERE booking__is_instant + ) subq_21 + ) subq_22 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_24.listing + , subq_24.is_lux_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_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.created_at__day + , subq_23.created_at__week + , subq_23.created_at__month + , subq_23.created_at__quarter + , subq_23.created_at__year + , subq_23.created_at__extract_year + , subq_23.created_at__extract_quarter + , subq_23.created_at__extract_month + , subq_23.created_at__extract_day + , subq_23.created_at__extract_dow + , subq_23.created_at__extract_doy + , subq_23.listing__ds__day + , subq_23.listing__ds__week + , subq_23.listing__ds__month + , subq_23.listing__ds__quarter + , subq_23.listing__ds__year + , subq_23.listing__ds__extract_year + , subq_23.listing__ds__extract_quarter + , subq_23.listing__ds__extract_month + , subq_23.listing__ds__extract_day + , subq_23.listing__ds__extract_dow + , subq_23.listing__ds__extract_doy + , subq_23.listing__created_at__day + , subq_23.listing__created_at__week + , subq_23.listing__created_at__month + , subq_23.listing__created_at__quarter + , subq_23.listing__created_at__year + , subq_23.listing__created_at__extract_year + , subq_23.listing__created_at__extract_quarter + , subq_23.listing__created_at__extract_month + , subq_23.listing__created_at__extract_day + , subq_23.listing__created_at__extract_dow + , subq_23.listing__created_at__extract_doy + , subq_23.ds__day AS metric_time__day + , subq_23.ds__week AS metric_time__week + , subq_23.ds__month AS metric_time__month + , subq_23.ds__quarter AS metric_time__quarter + , subq_23.ds__year AS metric_time__year + , subq_23.ds__extract_year AS metric_time__extract_year + , subq_23.ds__extract_quarter AS metric_time__extract_quarter + , subq_23.ds__extract_month AS metric_time__extract_month + , subq_23.ds__extract_day AS metric_time__extract_day + , subq_23.ds__extract_dow AS metric_time__extract_dow + , subq_23.ds__extract_doy AS metric_time__extract_doy + , subq_23.listing + , subq_23.user + , subq_23.listing__user + , subq_23.country_latest + , subq_23.is_lux_latest + , subq_23.capacity_latest + , subq_23.listing__country_latest + , subq_23.listing__is_lux_latest + , subq_23.listing__capacity_latest + , subq_23.listings + , subq_23.largest_listing + , subq_23.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ 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_23 + ) subq_24 + ) subq_25 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_22.listing = subq_25.listing + ) subq_26 + ) subq_27 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_28 + ) subq_29 + ) subq_30 + ) subq_31 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_38.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_37.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_36.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_35.booking__is_instant + , subq_35.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_34.booking__is_instant + , subq_34.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_33.ds__day + , subq_33.ds__week + , subq_33.ds__month + , subq_33.ds__quarter + , subq_33.ds__year + , subq_33.ds__extract_year + , subq_33.ds__extract_quarter + , subq_33.ds__extract_month + , subq_33.ds__extract_day + , subq_33.ds__extract_dow + , subq_33.ds__extract_doy + , subq_33.ds_partitioned__day + , subq_33.ds_partitioned__week + , subq_33.ds_partitioned__month + , subq_33.ds_partitioned__quarter + , subq_33.ds_partitioned__year + , subq_33.ds_partitioned__extract_year + , subq_33.ds_partitioned__extract_quarter + , subq_33.ds_partitioned__extract_month + , subq_33.ds_partitioned__extract_day + , subq_33.ds_partitioned__extract_dow + , subq_33.ds_partitioned__extract_doy + , subq_33.paid_at__day + , subq_33.paid_at__week + , subq_33.paid_at__month + , subq_33.paid_at__quarter + , subq_33.paid_at__year + , subq_33.paid_at__extract_year + , subq_33.paid_at__extract_quarter + , subq_33.paid_at__extract_month + , subq_33.paid_at__extract_day + , subq_33.paid_at__extract_dow + , subq_33.paid_at__extract_doy + , subq_33.booking__ds__day + , subq_33.booking__ds__week + , subq_33.booking__ds__month + , subq_33.booking__ds__quarter + , subq_33.booking__ds__year + , subq_33.booking__ds__extract_year + , subq_33.booking__ds__extract_quarter + , subq_33.booking__ds__extract_month + , subq_33.booking__ds__extract_day + , subq_33.booking__ds__extract_dow + , subq_33.booking__ds__extract_doy + , subq_33.booking__ds_partitioned__day + , subq_33.booking__ds_partitioned__week + , subq_33.booking__ds_partitioned__month + , subq_33.booking__ds_partitioned__quarter + , subq_33.booking__ds_partitioned__year + , subq_33.booking__ds_partitioned__extract_year + , subq_33.booking__ds_partitioned__extract_quarter + , subq_33.booking__ds_partitioned__extract_month + , subq_33.booking__ds_partitioned__extract_day + , subq_33.booking__ds_partitioned__extract_dow + , subq_33.booking__ds_partitioned__extract_doy + , subq_33.booking__paid_at__day + , subq_33.booking__paid_at__week + , subq_33.booking__paid_at__month + , subq_33.booking__paid_at__quarter + , subq_33.booking__paid_at__year + , subq_33.booking__paid_at__extract_year + , subq_33.booking__paid_at__extract_quarter + , subq_33.booking__paid_at__extract_month + , subq_33.booking__paid_at__extract_day + , subq_33.booking__paid_at__extract_dow + , subq_33.booking__paid_at__extract_doy + , subq_33.metric_time__day + , subq_33.metric_time__week + , subq_33.metric_time__month + , subq_33.metric_time__quarter + , subq_33.metric_time__year + , subq_33.metric_time__extract_year + , subq_33.metric_time__extract_quarter + , subq_33.metric_time__extract_month + , subq_33.metric_time__extract_day + , subq_33.metric_time__extract_dow + , subq_33.metric_time__extract_doy + , subq_33.listing + , subq_33.guest + , subq_33.host + , subq_33.booking__listing + , subq_33.booking__guest + , subq_33.booking__host + , subq_33.is_instant + , subq_33.booking__is_instant + , subq_33.bookings + , subq_33.instant_bookings + , subq_33.booking_value + , subq_33.max_booking_value + , subq_33.min_booking_value + , subq_33.bookers + , subq_33.average_booking_value + , subq_33.referred_bookings + , subq_33.median_booking_value + , subq_33.booking_value_p99 + , subq_33.discrete_booking_value_p99 + , subq_33.approximate_continuous_booking_value_p99 + , subq_33.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_24 - ) subq_25 - ) subq_26 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.ds__day AS metric_time__day + , subq_32.ds__week AS metric_time__week + , subq_32.ds__month AS metric_time__month + , subq_32.ds__quarter AS metric_time__quarter + , subq_32.ds__year AS metric_time__year + , subq_32.ds__extract_year AS metric_time__extract_year + , subq_32.ds__extract_quarter AS metric_time__extract_quarter + , subq_32.ds__extract_month AS metric_time__extract_month + , subq_32.ds__extract_day AS metric_time__extract_day + , subq_32.ds__extract_dow AS metric_time__extract_dow + , subq_32.ds__extract_doy AS metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 + 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_32 + ) subq_33 + WHERE booking__is_instant + ) subq_34 + ) subq_35 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_36 + ) subq_37 + ) subq_38 + ) subq_39 + ) subq_40 +) subq_41 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0_optimized.sql index a73bfea928..60a09b752b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_54.average_booking_value) AS average_booking_value + , MAX(subq_67.bookings) AS bookings + , MAX(subq_75.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_45.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_45.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_43 + WHERE booking__is_instant + ) subq_45 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_45.listing = listings_latest_src_28000.listing_id + ) subq_50 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_54 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_58.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_58.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_56 + WHERE booking__is_instant + ) subq_58 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_58.listing = listings_latest_src_28000.listing_id + ) subq_63 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_67 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_69 + WHERE booking__is_instant + ) subq_71 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_75 + ) subq_76 +) subq_77 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0.sql index 9edb0371c0..6fea622708 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0.sql @@ -8,317 +8,420 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_18.average_booking_value) AS average_booking_value + , MAX(subq_31.bookings) AS bookings + , MAX(subq_39.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_17.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_16.average_booking_value) AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_15.average_booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_14.booking__is_instant + , subq_14.listing__is_lux_latest + , subq_14.average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_13.booking__is_instant + , subq_13.listing__is_lux_latest + , subq_13.average_booking_value FROM ( -- Join Standard Outputs SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value + subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_12.is_lux_latest AS listing__is_lux_latest + , subq_9.average_booking_value AS average_booking_value FROM ( -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value + subq_8.listing + , subq_8.booking__is_instant + , subq_8.average_booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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__day + , 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 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_4.listing - , subq_4.is_lux_latest + subq_11.listing + , subq_11.is_lux_latest FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day + , subq_10.created_at__week + , subq_10.created_at__month + , subq_10.created_at__quarter + , subq_10.created_at__year + , subq_10.created_at__extract_year + , subq_10.created_at__extract_quarter + , subq_10.created_at__extract_month + , subq_10.created_at__extract_day + , subq_10.created_at__extract_dow + , subq_10.created_at__extract_doy + , subq_10.listing__ds__day + , subq_10.listing__ds__week + , subq_10.listing__ds__month + , subq_10.listing__ds__quarter + , subq_10.listing__ds__year + , subq_10.listing__ds__extract_year + , subq_10.listing__ds__extract_quarter + , subq_10.listing__ds__extract_month + , subq_10.listing__ds__extract_day + , subq_10.listing__ds__extract_dow + , subq_10.listing__ds__extract_doy + , subq_10.listing__created_at__day + , subq_10.listing__created_at__week + , subq_10.listing__created_at__month + , subq_10.listing__created_at__quarter + , subq_10.listing__created_at__year + , subq_10.listing__created_at__extract_year + , subq_10.listing__created_at__extract_quarter + , subq_10.listing__created_at__extract_month + , subq_10.listing__created_at__extract_day + , subq_10.listing__created_at__extract_dow + , subq_10.listing__created_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.user + , subq_10.listing__user + , subq_10.country_latest + , subq_10.is_lux_latest + , subq_10.capacity_latest + , subq_10.listing__country_latest + , subq_10.listing__is_lux_latest + , subq_10.listing__capacity_latest + , subq_10.listings + , subq_10.largest_listing + , subq_10.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -379,326 +482,429 @@ 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_3 - ) subq_4 - ) subq_5 + ) subq_10 + ) subq_11 + ) subq_12 ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + subq_9.listing = subq_12.listing + ) subq_13 + ) subq_14 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + ) subq_15 + ) subq_16 + ) subq_17 + ) subq_18 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_30.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_29.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_28.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_27.booking__is_instant + , subq_27.listing__is_lux_latest + , subq_27.bookings FROM ( -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_26.booking__is_instant + , subq_26.listing__is_lux_latest + , subq_26.bookings FROM ( -- Join Standard Outputs SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings + subq_22.listing AS listing + , subq_22.booking__is_instant AS booking__is_instant + , subq_25.is_lux_latest AS listing__is_lux_latest + , subq_22.bookings AS bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings + subq_21.listing + , subq_21.booking__is_instant + , subq_21.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 + 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.ds_partitioned__day + , subq_20.ds_partitioned__week + , subq_20.ds_partitioned__month + , subq_20.ds_partitioned__quarter + , subq_20.ds_partitioned__year + , subq_20.ds_partitioned__extract_year + , subq_20.ds_partitioned__extract_quarter + , subq_20.ds_partitioned__extract_month + , subq_20.ds_partitioned__extract_day + , subq_20.ds_partitioned__extract_dow + , subq_20.ds_partitioned__extract_doy + , subq_20.paid_at__day + , subq_20.paid_at__week + , subq_20.paid_at__month + , subq_20.paid_at__quarter + , subq_20.paid_at__year + , subq_20.paid_at__extract_year + , subq_20.paid_at__extract_quarter + , subq_20.paid_at__extract_month + , subq_20.paid_at__extract_day + , subq_20.paid_at__extract_dow + , subq_20.paid_at__extract_doy + , subq_20.booking__ds__day + , subq_20.booking__ds__week + , subq_20.booking__ds__month + , subq_20.booking__ds__quarter + , subq_20.booking__ds__year + , subq_20.booking__ds__extract_year + , subq_20.booking__ds__extract_quarter + , subq_20.booking__ds__extract_month + , subq_20.booking__ds__extract_day + , subq_20.booking__ds__extract_dow + , subq_20.booking__ds__extract_doy + , subq_20.booking__ds_partitioned__day + , subq_20.booking__ds_partitioned__week + , subq_20.booking__ds_partitioned__month + , subq_20.booking__ds_partitioned__quarter + , subq_20.booking__ds_partitioned__year + , subq_20.booking__ds_partitioned__extract_year + , subq_20.booking__ds_partitioned__extract_quarter + , subq_20.booking__ds_partitioned__extract_month + , subq_20.booking__ds_partitioned__extract_day + , subq_20.booking__ds_partitioned__extract_dow + , subq_20.booking__ds_partitioned__extract_doy + , subq_20.booking__paid_at__day + , subq_20.booking__paid_at__week + , subq_20.booking__paid_at__month + , subq_20.booking__paid_at__quarter + , subq_20.booking__paid_at__year + , subq_20.booking__paid_at__extract_year + , subq_20.booking__paid_at__extract_quarter + , subq_20.booking__paid_at__extract_month + , subq_20.booking__paid_at__extract_day + , subq_20.booking__paid_at__extract_dow + , subq_20.booking__paid_at__extract_doy + , subq_20.metric_time__day + , subq_20.metric_time__week + , subq_20.metric_time__month + , subq_20.metric_time__quarter + , subq_20.metric_time__year + , subq_20.metric_time__extract_year + , subq_20.metric_time__extract_quarter + , subq_20.metric_time__extract_month + , subq_20.metric_time__extract_day + , subq_20.metric_time__extract_dow + , subq_20.metric_time__extract_doy + , subq_20.listing + , subq_20.guest + , subq_20.host + , subq_20.booking__listing + , subq_20.booking__guest + , subq_20.booking__host + , subq_20.is_instant + , subq_20.booking__is_instant + , subq_20.bookings + , subq_20.instant_bookings + , subq_20.booking_value + , subq_20.max_booking_value + , subq_20.min_booking_value + , subq_20.bookers + , subq_20.average_booking_value + , subq_20.referred_bookings + , subq_20.median_booking_value + , subq_20.booking_value_p99 + , subq_20.discrete_booking_value_p99 + , subq_20.approximate_continuous_booking_value_p99 + , subq_20.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_12 - ) subq_13 - ) subq_14 + 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.ds__day AS metric_time__day + , subq_19.ds__week AS metric_time__week + , subq_19.ds__month AS metric_time__month + , subq_19.ds__quarter AS metric_time__quarter + , subq_19.ds__year AS metric_time__year + , subq_19.ds__extract_year AS metric_time__extract_year + , subq_19.ds__extract_quarter AS metric_time__extract_quarter + , subq_19.ds__extract_month AS metric_time__extract_month + , subq_19.ds__extract_day AS metric_time__extract_day + , subq_19.ds__extract_dow AS metric_time__extract_dow + , subq_19.ds__extract_doy AS metric_time__extract_doy + , 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.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 ( + -- 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_19 + ) subq_20 + WHERE booking__is_instant + ) subq_21 + ) subq_22 LEFT OUTER JOIN ( -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_16.listing - , subq_16.is_lux_latest + subq_24.listing + , subq_24.is_lux_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_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.created_at__day + , subq_23.created_at__week + , subq_23.created_at__month + , subq_23.created_at__quarter + , subq_23.created_at__year + , subq_23.created_at__extract_year + , subq_23.created_at__extract_quarter + , subq_23.created_at__extract_month + , subq_23.created_at__extract_day + , subq_23.created_at__extract_dow + , subq_23.created_at__extract_doy + , subq_23.listing__ds__day + , subq_23.listing__ds__week + , subq_23.listing__ds__month + , subq_23.listing__ds__quarter + , subq_23.listing__ds__year + , subq_23.listing__ds__extract_year + , subq_23.listing__ds__extract_quarter + , subq_23.listing__ds__extract_month + , subq_23.listing__ds__extract_day + , subq_23.listing__ds__extract_dow + , subq_23.listing__ds__extract_doy + , subq_23.listing__created_at__day + , subq_23.listing__created_at__week + , subq_23.listing__created_at__month + , subq_23.listing__created_at__quarter + , subq_23.listing__created_at__year + , subq_23.listing__created_at__extract_year + , subq_23.listing__created_at__extract_quarter + , subq_23.listing__created_at__extract_month + , subq_23.listing__created_at__extract_day + , subq_23.listing__created_at__extract_dow + , subq_23.listing__created_at__extract_doy + , subq_23.ds__day AS metric_time__day + , subq_23.ds__week AS metric_time__week + , subq_23.ds__month AS metric_time__month + , subq_23.ds__quarter AS metric_time__quarter + , subq_23.ds__year AS metric_time__year + , subq_23.ds__extract_year AS metric_time__extract_year + , subq_23.ds__extract_quarter AS metric_time__extract_quarter + , subq_23.ds__extract_month AS metric_time__extract_month + , subq_23.ds__extract_day AS metric_time__extract_day + , subq_23.ds__extract_dow AS metric_time__extract_dow + , subq_23.ds__extract_doy AS metric_time__extract_doy + , subq_23.listing + , subq_23.user + , subq_23.listing__user + , subq_23.country_latest + , subq_23.is_lux_latest + , subq_23.capacity_latest + , subq_23.listing__country_latest + , subq_23.listing__is_lux_latest + , subq_23.listing__capacity_latest + , subq_23.listings + , subq_23.largest_listing + , subq_23.smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -759,240 +965,343 @@ 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_23 + ) subq_24 + ) subq_25 ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 + subq_22.listing = subq_25.listing + ) subq_26 + ) subq_27 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + ) subq_28 + ) subq_29 + ) subq_30 + ) subq_31 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_38.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_37.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_36.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_35.booking__is_instant + , subq_35.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_25.booking__is_instant - , subq_25.booking_value + subq_34.booking__is_instant + , subq_34.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 + subq_33.ds__day + , subq_33.ds__week + , subq_33.ds__month + , subq_33.ds__quarter + , subq_33.ds__year + , subq_33.ds__extract_year + , subq_33.ds__extract_quarter + , subq_33.ds__extract_month + , subq_33.ds__extract_day + , subq_33.ds__extract_dow + , subq_33.ds__extract_doy + , subq_33.ds_partitioned__day + , subq_33.ds_partitioned__week + , subq_33.ds_partitioned__month + , subq_33.ds_partitioned__quarter + , subq_33.ds_partitioned__year + , subq_33.ds_partitioned__extract_year + , subq_33.ds_partitioned__extract_quarter + , subq_33.ds_partitioned__extract_month + , subq_33.ds_partitioned__extract_day + , subq_33.ds_partitioned__extract_dow + , subq_33.ds_partitioned__extract_doy + , subq_33.paid_at__day + , subq_33.paid_at__week + , subq_33.paid_at__month + , subq_33.paid_at__quarter + , subq_33.paid_at__year + , subq_33.paid_at__extract_year + , subq_33.paid_at__extract_quarter + , subq_33.paid_at__extract_month + , subq_33.paid_at__extract_day + , subq_33.paid_at__extract_dow + , subq_33.paid_at__extract_doy + , subq_33.booking__ds__day + , subq_33.booking__ds__week + , subq_33.booking__ds__month + , subq_33.booking__ds__quarter + , subq_33.booking__ds__year + , subq_33.booking__ds__extract_year + , subq_33.booking__ds__extract_quarter + , subq_33.booking__ds__extract_month + , subq_33.booking__ds__extract_day + , subq_33.booking__ds__extract_dow + , subq_33.booking__ds__extract_doy + , subq_33.booking__ds_partitioned__day + , subq_33.booking__ds_partitioned__week + , subq_33.booking__ds_partitioned__month + , subq_33.booking__ds_partitioned__quarter + , subq_33.booking__ds_partitioned__year + , subq_33.booking__ds_partitioned__extract_year + , subq_33.booking__ds_partitioned__extract_quarter + , subq_33.booking__ds_partitioned__extract_month + , subq_33.booking__ds_partitioned__extract_day + , subq_33.booking__ds_partitioned__extract_dow + , subq_33.booking__ds_partitioned__extract_doy + , subq_33.booking__paid_at__day + , subq_33.booking__paid_at__week + , subq_33.booking__paid_at__month + , subq_33.booking__paid_at__quarter + , subq_33.booking__paid_at__year + , subq_33.booking__paid_at__extract_year + , subq_33.booking__paid_at__extract_quarter + , subq_33.booking__paid_at__extract_month + , subq_33.booking__paid_at__extract_day + , subq_33.booking__paid_at__extract_dow + , subq_33.booking__paid_at__extract_doy + , subq_33.metric_time__day + , subq_33.metric_time__week + , subq_33.metric_time__month + , subq_33.metric_time__quarter + , subq_33.metric_time__year + , subq_33.metric_time__extract_year + , subq_33.metric_time__extract_quarter + , subq_33.metric_time__extract_month + , subq_33.metric_time__extract_day + , subq_33.metric_time__extract_dow + , subq_33.metric_time__extract_doy + , subq_33.listing + , subq_33.guest + , subq_33.host + , subq_33.booking__listing + , subq_33.booking__guest + , subq_33.booking__host + , subq_33.is_instant + , subq_33.booking__is_instant + , subq_33.bookings + , subq_33.instant_bookings + , subq_33.booking_value + , subq_33.max_booking_value + , subq_33.min_booking_value + , subq_33.bookers + , subq_33.average_booking_value + , subq_33.referred_bookings + , subq_33.median_booking_value + , subq_33.booking_value_p99 + , subq_33.discrete_booking_value_p99 + , subq_33.approximate_continuous_booking_value_p99 + , subq_33.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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_24 - ) subq_25 - ) subq_26 + subq_32.ds__day + , subq_32.ds__week + , subq_32.ds__month + , subq_32.ds__quarter + , subq_32.ds__year + , subq_32.ds__extract_year + , subq_32.ds__extract_quarter + , subq_32.ds__extract_month + , subq_32.ds__extract_day + , subq_32.ds__extract_dow + , subq_32.ds__extract_doy + , subq_32.ds_partitioned__day + , subq_32.ds_partitioned__week + , subq_32.ds_partitioned__month + , subq_32.ds_partitioned__quarter + , subq_32.ds_partitioned__year + , subq_32.ds_partitioned__extract_year + , subq_32.ds_partitioned__extract_quarter + , subq_32.ds_partitioned__extract_month + , subq_32.ds_partitioned__extract_day + , subq_32.ds_partitioned__extract_dow + , subq_32.ds_partitioned__extract_doy + , subq_32.paid_at__day + , subq_32.paid_at__week + , subq_32.paid_at__month + , subq_32.paid_at__quarter + , subq_32.paid_at__year + , subq_32.paid_at__extract_year + , subq_32.paid_at__extract_quarter + , subq_32.paid_at__extract_month + , subq_32.paid_at__extract_day + , subq_32.paid_at__extract_dow + , subq_32.paid_at__extract_doy + , subq_32.booking__ds__day + , subq_32.booking__ds__week + , subq_32.booking__ds__month + , subq_32.booking__ds__quarter + , subq_32.booking__ds__year + , subq_32.booking__ds__extract_year + , subq_32.booking__ds__extract_quarter + , subq_32.booking__ds__extract_month + , subq_32.booking__ds__extract_day + , subq_32.booking__ds__extract_dow + , subq_32.booking__ds__extract_doy + , subq_32.booking__ds_partitioned__day + , subq_32.booking__ds_partitioned__week + , subq_32.booking__ds_partitioned__month + , subq_32.booking__ds_partitioned__quarter + , subq_32.booking__ds_partitioned__year + , subq_32.booking__ds_partitioned__extract_year + , subq_32.booking__ds_partitioned__extract_quarter + , subq_32.booking__ds_partitioned__extract_month + , subq_32.booking__ds_partitioned__extract_day + , subq_32.booking__ds_partitioned__extract_dow + , subq_32.booking__ds_partitioned__extract_doy + , subq_32.booking__paid_at__day + , subq_32.booking__paid_at__week + , subq_32.booking__paid_at__month + , subq_32.booking__paid_at__quarter + , subq_32.booking__paid_at__year + , subq_32.booking__paid_at__extract_year + , subq_32.booking__paid_at__extract_quarter + , subq_32.booking__paid_at__extract_month + , subq_32.booking__paid_at__extract_day + , subq_32.booking__paid_at__extract_dow + , subq_32.booking__paid_at__extract_doy + , subq_32.ds__day AS metric_time__day + , subq_32.ds__week AS metric_time__week + , subq_32.ds__month AS metric_time__month + , subq_32.ds__quarter AS metric_time__quarter + , subq_32.ds__year AS metric_time__year + , subq_32.ds__extract_year AS metric_time__extract_year + , subq_32.ds__extract_quarter AS metric_time__extract_quarter + , subq_32.ds__extract_month AS metric_time__extract_month + , subq_32.ds__extract_day AS metric_time__extract_day + , subq_32.ds__extract_dow AS metric_time__extract_dow + , subq_32.ds__extract_doy AS metric_time__extract_doy + , subq_32.listing + , subq_32.guest + , subq_32.host + , subq_32.booking__listing + , subq_32.booking__guest + , subq_32.booking__host + , subq_32.is_instant + , subq_32.booking__is_instant + , subq_32.bookings + , subq_32.instant_bookings + , subq_32.booking_value + , subq_32.max_booking_value + , subq_32.min_booking_value + , subq_32.bookers + , subq_32.average_booking_value + , subq_32.referred_bookings + , subq_32.median_booking_value + , subq_32.booking_value_p99 + , subq_32.discrete_booking_value_p99 + , subq_32.approximate_continuous_booking_value_p99 + , subq_32.approximate_discrete_booking_value_p99 + 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_32 + ) subq_33 + WHERE booking__is_instant + ) subq_34 + ) subq_35 WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + ) subq_36 + ) subq_37 + ) subq_38 + ) subq_39 + ) subq_40 +) subq_41 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0_optimized.sql index a73bfea928..60a09b752b 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_56.bookings) AS bookings - , MAX(subq_63.booking_value) AS booking_value + MAX(subq_54.average_booking_value) AS average_booking_value + , MAX(subq_67.bookings) AS bookings + , MAX(subq_75.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] @@ -22,17 +22,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - bookings_source_src_28000.is_instant AS booking__is_instant + subq_45.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , bookings_source_src_28000.booking_value AS average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 + , subq_45.average_booking_value AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_43 + WHERE booking__is_instant + ) subq_45 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - ) subq_40 + subq_45.listing = listings_latest_src_28000.listing_id + ) subq_50 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_54 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] @@ -44,26 +61,34 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_47.booking__is_instant AS booking__is_instant + subq_58.booking__is_instant AS booking__is_instant , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_47.bookings AS bookings + , subq_58.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - listing_id AS listing - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_56 + WHERE booking__is_instant + ) subq_58 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_47.listing = listings_latest_src_28000.listing_id - ) subq_52 + subq_58.listing = listings_latest_src_28000.listing_id + ) subq_63 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_56 + ) subq_67 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -72,15 +97,22 @@ FROM ( SELECT SUM(booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - is_instant AS booking__is_instant + booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_59 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_69 + WHERE booking__is_instant + ) subq_71 WHERE booking__is_instant - ) subq_63 - ) subq_64 -) subq_65 + ) subq_75 + ) subq_76 +) subq_77 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0.sql index 545abe7b6a..55f1ad847b 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_25.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_24.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_23.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_22.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_22.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_21.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_21.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_11.customer_third_hop_id AS customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_11.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_10.customer_third_hop_id + , subq_10.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_9.third_hop_ds__day + , subq_9.third_hop_ds__week + , subq_9.third_hop_ds__month + , subq_9.third_hop_ds__quarter + , subq_9.third_hop_ds__year + , subq_9.third_hop_ds__extract_year + , subq_9.third_hop_ds__extract_quarter + , subq_9.third_hop_ds__extract_month + , subq_9.third_hop_ds__extract_day + , subq_9.third_hop_ds__extract_dow + , subq_9.third_hop_ds__extract_doy + , subq_9.customer_third_hop_id__third_hop_ds__day + , subq_9.customer_third_hop_id__third_hop_ds__week + , subq_9.customer_third_hop_id__third_hop_ds__month + , subq_9.customer_third_hop_id__third_hop_ds__quarter + , subq_9.customer_third_hop_id__third_hop_ds__year + , subq_9.customer_third_hop_id__third_hop_ds__extract_year + , subq_9.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_9.customer_third_hop_id__third_hop_ds__extract_month + , subq_9.customer_third_hop_id__third_hop_ds__extract_day + , subq_9.customer_third_hop_id__third_hop_ds__extract_dow + , subq_9.customer_third_hop_id__third_hop_ds__extract_doy + , subq_9.third_hop_ds__day AS metric_time__day + , subq_9.third_hop_ds__week AS metric_time__week + , subq_9.third_hop_ds__month AS metric_time__month + , subq_9.third_hop_ds__quarter AS metric_time__quarter + , subq_9.third_hop_ds__year AS metric_time__year + , subq_9.third_hop_ds__extract_year AS metric_time__extract_year + , subq_9.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_9.third_hop_ds__extract_month AS metric_time__extract_month + , subq_9.third_hop_ds__extract_day AS metric_time__extract_day + , subq_9.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_9.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_9.customer_third_hop_id + , subq_9.value + , subq_9.customer_third_hop_id__value + , subq_9.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(dayofyear FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_19.customer_id__customer_third_hop_id + , subq_19.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , SUM(subq_17.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_15.customer_id__customer_third_hop_id + , subq_15.customer_id__country + , subq_15.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_14.customer_id__customer_third_hop_id + , subq_14.customer_id__country + , subq_14.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_13.acquired_ds__day + , subq_13.acquired_ds__week + , subq_13.acquired_ds__month + , subq_13.acquired_ds__quarter + , subq_13.acquired_ds__year + , subq_13.acquired_ds__extract_year + , subq_13.acquired_ds__extract_quarter + , subq_13.acquired_ds__extract_month + , subq_13.acquired_ds__extract_day + , subq_13.acquired_ds__extract_dow + , subq_13.acquired_ds__extract_doy + , subq_13.customer_id__acquired_ds__day + , subq_13.customer_id__acquired_ds__week + , subq_13.customer_id__acquired_ds__month + , subq_13.customer_id__acquired_ds__quarter + , subq_13.customer_id__acquired_ds__year + , subq_13.customer_id__acquired_ds__extract_year + , subq_13.customer_id__acquired_ds__extract_quarter + , subq_13.customer_id__acquired_ds__extract_month + , subq_13.customer_id__acquired_ds__extract_day + , subq_13.customer_id__acquired_ds__extract_dow + , subq_13.customer_id__acquired_ds__extract_doy + , subq_13.customer_third_hop_id__acquired_ds__day + , subq_13.customer_third_hop_id__acquired_ds__week + , subq_13.customer_third_hop_id__acquired_ds__month + , subq_13.customer_third_hop_id__acquired_ds__quarter + , subq_13.customer_third_hop_id__acquired_ds__year + , subq_13.customer_third_hop_id__acquired_ds__extract_year + , subq_13.customer_third_hop_id__acquired_ds__extract_quarter + , subq_13.customer_third_hop_id__acquired_ds__extract_month + , subq_13.customer_third_hop_id__acquired_ds__extract_day + , subq_13.customer_third_hop_id__acquired_ds__extract_dow + , subq_13.customer_third_hop_id__acquired_ds__extract_doy + , subq_13.metric_time__day + , subq_13.metric_time__week + , subq_13.metric_time__month + , subq_13.metric_time__quarter + , subq_13.metric_time__year + , subq_13.metric_time__extract_year + , subq_13.metric_time__extract_quarter + , subq_13.metric_time__extract_month + , subq_13.metric_time__extract_day + , subq_13.metric_time__extract_dow + , subq_13.metric_time__extract_doy + , subq_13.customer_id + , subq_13.customer_third_hop_id + , subq_13.customer_id__customer_third_hop_id + , subq_13.customer_third_hop_id__customer_id + , subq_13.country + , subq_13.customer_id__country + , subq_13.customer_third_hop_id__country + , subq_13.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS acquired_ds__day - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS acquired_ds__week - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS acquired_ds__month - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS acquired_ds__quarter - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS acquired_ds__extract_dow - , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS customer_id__acquired_ds__day - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS customer_id__acquired_ds__week - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS customer_id__acquired_ds__month - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS customer_id__acquired_ds__quarter - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS customer_id__acquired_ds__extract_dow - , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS customer_third_hop_id__acquired_ds__day - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS customer_third_hop_id__acquired_ds__week - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS customer_third_hop_id__acquired_ds__month - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS customer_third_hop_id__acquired_ds__quarter - , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_12.acquired_ds__day + , subq_12.acquired_ds__week + , subq_12.acquired_ds__month + , subq_12.acquired_ds__quarter + , subq_12.acquired_ds__year + , subq_12.acquired_ds__extract_year + , subq_12.acquired_ds__extract_quarter + , subq_12.acquired_ds__extract_month + , subq_12.acquired_ds__extract_day + , subq_12.acquired_ds__extract_dow + , subq_12.acquired_ds__extract_doy + , subq_12.customer_id__acquired_ds__day + , subq_12.customer_id__acquired_ds__week + , subq_12.customer_id__acquired_ds__month + , subq_12.customer_id__acquired_ds__quarter + , subq_12.customer_id__acquired_ds__year + , subq_12.customer_id__acquired_ds__extract_year + , subq_12.customer_id__acquired_ds__extract_quarter + , subq_12.customer_id__acquired_ds__extract_month + , subq_12.customer_id__acquired_ds__extract_day + , subq_12.customer_id__acquired_ds__extract_dow + , subq_12.customer_id__acquired_ds__extract_doy + , subq_12.customer_third_hop_id__acquired_ds__day + , subq_12.customer_third_hop_id__acquired_ds__week + , subq_12.customer_third_hop_id__acquired_ds__month + , subq_12.customer_third_hop_id__acquired_ds__quarter + , subq_12.customer_third_hop_id__acquired_ds__year + , subq_12.customer_third_hop_id__acquired_ds__extract_year + , subq_12.customer_third_hop_id__acquired_ds__extract_quarter + , subq_12.customer_third_hop_id__acquired_ds__extract_month + , subq_12.customer_third_hop_id__acquired_ds__extract_day + , subq_12.customer_third_hop_id__acquired_ds__extract_dow + , subq_12.customer_third_hop_id__acquired_ds__extract_doy + , subq_12.acquired_ds__day AS metric_time__day + , subq_12.acquired_ds__week AS metric_time__week + , subq_12.acquired_ds__month AS metric_time__month + , subq_12.acquired_ds__quarter AS metric_time__quarter + , subq_12.acquired_ds__year AS metric_time__year + , subq_12.acquired_ds__extract_year AS metric_time__extract_year + , subq_12.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_12.acquired_ds__extract_month AS metric_time__extract_month + , subq_12.acquired_ds__extract_day AS metric_time__extract_day + , subq_12.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_12.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_12.customer_id + , subq_12.customer_third_hop_id + , subq_12.customer_id__customer_third_hop_id + , subq_12.customer_third_hop_id__customer_id + , subq_12.country + , subq_12.customer_id__country + , subq_12.customer_third_hop_id__country + , subq_12.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS acquired_ds__day + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS acquired_ds__week + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS acquired_ds__month + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS acquired_ds__quarter + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS acquired_ds__extract_dow + , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS customer_id__acquired_ds__day + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS customer_id__acquired_ds__week + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS customer_id__acquired_ds__month + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS customer_id__acquired_ds__quarter + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS customer_id__acquired_ds__extract_dow + , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, day) AS customer_third_hop_id__acquired_ds__day + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, isoweek) AS customer_third_hop_id__acquired_ds__week + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, month) AS customer_third_hop_id__acquired_ds__month + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, quarter) AS customer_third_hop_id__acquired_ds__quarter + , DATETIME_TRUNC(customer_other_data_src_22000.acquired_ds, year) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , IF(EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) = 1, 7, EXTRACT(dayofweek FROM customer_other_data_src_22000.acquired_ds) - 1) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(dayofyear FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_12 + ) subq_13 + WHERE customer_id__country = 'paraguay' + ) subq_14 + ) subq_15 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_16 + ) subq_17 GROUP BY customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + ) subq_18 + ) subq_19 + ) subq_20 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_11.customer_third_hop_id = subq_20.customer_id__customer_third_hop_id + ) subq_21 + ) subq_22 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_23 + ) subq_24 +) subq_25 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..4af49531fb 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/BigQuery/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_37.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_30 + WHERE customer_id__country = 'paraguay' + ) subq_32 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_37 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_37.customer_id__customer_third_hop_id +) subq_39 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0.sql index 41388a6d9b..b53d8d1142 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_25.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_24.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_23.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_22.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_22.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_21.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_21.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_11.customer_third_hop_id AS customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_11.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_10.customer_third_hop_id + , subq_10.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_9.third_hop_ds__day + , subq_9.third_hop_ds__week + , subq_9.third_hop_ds__month + , subq_9.third_hop_ds__quarter + , subq_9.third_hop_ds__year + , subq_9.third_hop_ds__extract_year + , subq_9.third_hop_ds__extract_quarter + , subq_9.third_hop_ds__extract_month + , subq_9.third_hop_ds__extract_day + , subq_9.third_hop_ds__extract_dow + , subq_9.third_hop_ds__extract_doy + , subq_9.customer_third_hop_id__third_hop_ds__day + , subq_9.customer_third_hop_id__third_hop_ds__week + , subq_9.customer_third_hop_id__third_hop_ds__month + , subq_9.customer_third_hop_id__third_hop_ds__quarter + , subq_9.customer_third_hop_id__third_hop_ds__year + , subq_9.customer_third_hop_id__third_hop_ds__extract_year + , subq_9.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_9.customer_third_hop_id__third_hop_ds__extract_month + , subq_9.customer_third_hop_id__third_hop_ds__extract_day + , subq_9.customer_third_hop_id__third_hop_ds__extract_dow + , subq_9.customer_third_hop_id__third_hop_ds__extract_doy + , subq_9.third_hop_ds__day AS metric_time__day + , subq_9.third_hop_ds__week AS metric_time__week + , subq_9.third_hop_ds__month AS metric_time__month + , subq_9.third_hop_ds__quarter AS metric_time__quarter + , subq_9.third_hop_ds__year AS metric_time__year + , subq_9.third_hop_ds__extract_year AS metric_time__extract_year + , subq_9.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_9.third_hop_ds__extract_month AS metric_time__extract_month + , subq_9.third_hop_ds__extract_day AS metric_time__extract_day + , subq_9.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_9.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_9.customer_third_hop_id + , subq_9.value + , subq_9.customer_third_hop_id__value + , subq_9.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_19.customer_id__customer_third_hop_id + , subq_19.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , SUM(subq_17.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_15.customer_id__customer_third_hop_id + , subq_15.customer_id__country + , subq_15.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_14.customer_id__customer_third_hop_id + , subq_14.customer_id__country + , subq_14.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_13.acquired_ds__day + , subq_13.acquired_ds__week + , subq_13.acquired_ds__month + , subq_13.acquired_ds__quarter + , subq_13.acquired_ds__year + , subq_13.acquired_ds__extract_year + , subq_13.acquired_ds__extract_quarter + , subq_13.acquired_ds__extract_month + , subq_13.acquired_ds__extract_day + , subq_13.acquired_ds__extract_dow + , subq_13.acquired_ds__extract_doy + , subq_13.customer_id__acquired_ds__day + , subq_13.customer_id__acquired_ds__week + , subq_13.customer_id__acquired_ds__month + , subq_13.customer_id__acquired_ds__quarter + , subq_13.customer_id__acquired_ds__year + , subq_13.customer_id__acquired_ds__extract_year + , subq_13.customer_id__acquired_ds__extract_quarter + , subq_13.customer_id__acquired_ds__extract_month + , subq_13.customer_id__acquired_ds__extract_day + , subq_13.customer_id__acquired_ds__extract_dow + , subq_13.customer_id__acquired_ds__extract_doy + , subq_13.customer_third_hop_id__acquired_ds__day + , subq_13.customer_third_hop_id__acquired_ds__week + , subq_13.customer_third_hop_id__acquired_ds__month + , subq_13.customer_third_hop_id__acquired_ds__quarter + , subq_13.customer_third_hop_id__acquired_ds__year + , subq_13.customer_third_hop_id__acquired_ds__extract_year + , subq_13.customer_third_hop_id__acquired_ds__extract_quarter + , subq_13.customer_third_hop_id__acquired_ds__extract_month + , subq_13.customer_third_hop_id__acquired_ds__extract_day + , subq_13.customer_third_hop_id__acquired_ds__extract_dow + , subq_13.customer_third_hop_id__acquired_ds__extract_doy + , subq_13.metric_time__day + , subq_13.metric_time__week + , subq_13.metric_time__month + , subq_13.metric_time__quarter + , subq_13.metric_time__year + , subq_13.metric_time__extract_year + , subq_13.metric_time__extract_quarter + , subq_13.metric_time__extract_month + , subq_13.metric_time__extract_day + , subq_13.metric_time__extract_dow + , subq_13.metric_time__extract_doy + , subq_13.customer_id + , subq_13.customer_third_hop_id + , subq_13.customer_id__customer_third_hop_id + , subq_13.customer_third_hop_id__customer_id + , subq_13.country + , subq_13.customer_id__country + , subq_13.customer_third_hop_id__country + , subq_13.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_12.acquired_ds__day + , subq_12.acquired_ds__week + , subq_12.acquired_ds__month + , subq_12.acquired_ds__quarter + , subq_12.acquired_ds__year + , subq_12.acquired_ds__extract_year + , subq_12.acquired_ds__extract_quarter + , subq_12.acquired_ds__extract_month + , subq_12.acquired_ds__extract_day + , subq_12.acquired_ds__extract_dow + , subq_12.acquired_ds__extract_doy + , subq_12.customer_id__acquired_ds__day + , subq_12.customer_id__acquired_ds__week + , subq_12.customer_id__acquired_ds__month + , subq_12.customer_id__acquired_ds__quarter + , subq_12.customer_id__acquired_ds__year + , subq_12.customer_id__acquired_ds__extract_year + , subq_12.customer_id__acquired_ds__extract_quarter + , subq_12.customer_id__acquired_ds__extract_month + , subq_12.customer_id__acquired_ds__extract_day + , subq_12.customer_id__acquired_ds__extract_dow + , subq_12.customer_id__acquired_ds__extract_doy + , subq_12.customer_third_hop_id__acquired_ds__day + , subq_12.customer_third_hop_id__acquired_ds__week + , subq_12.customer_third_hop_id__acquired_ds__month + , subq_12.customer_third_hop_id__acquired_ds__quarter + , subq_12.customer_third_hop_id__acquired_ds__year + , subq_12.customer_third_hop_id__acquired_ds__extract_year + , subq_12.customer_third_hop_id__acquired_ds__extract_quarter + , subq_12.customer_third_hop_id__acquired_ds__extract_month + , subq_12.customer_third_hop_id__acquired_ds__extract_day + , subq_12.customer_third_hop_id__acquired_ds__extract_dow + , subq_12.customer_third_hop_id__acquired_ds__extract_doy + , subq_12.acquired_ds__day AS metric_time__day + , subq_12.acquired_ds__week AS metric_time__week + , subq_12.acquired_ds__month AS metric_time__month + , subq_12.acquired_ds__quarter AS metric_time__quarter + , subq_12.acquired_ds__year AS metric_time__year + , subq_12.acquired_ds__extract_year AS metric_time__extract_year + , subq_12.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_12.acquired_ds__extract_month AS metric_time__extract_month + , subq_12.acquired_ds__extract_day AS metric_time__extract_day + , subq_12.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_12.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_12.customer_id + , subq_12.customer_third_hop_id + , subq_12.customer_id__customer_third_hop_id + , subq_12.customer_third_hop_id__customer_id + , subq_12.country + , subq_12.customer_id__country + , subq_12.customer_third_hop_id__country + , subq_12.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_12 + ) subq_13 + WHERE customer_id__country = 'paraguay' + ) subq_14 + ) subq_15 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_16 + ) subq_17 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_17.customer_id__customer_third_hop_id + ) subq_18 + ) subq_19 + ) subq_20 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_11.customer_third_hop_id = subq_20.customer_id__customer_third_hop_id + ) subq_21 + ) subq_22 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_23 + ) subq_24 +) subq_25 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..4af49531fb 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Databricks/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_37.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_30 + WHERE customer_id__country = 'paraguay' + ) subq_32 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_37 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_37.customer_id__customer_third_hop_id +) subq_39 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql index 6a27e35c22..7e727a5e96 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_25.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_24.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_23.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_22.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_22.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_21.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_21.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_11.customer_third_hop_id AS customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_11.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_10.customer_third_hop_id + , subq_10.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_9.third_hop_ds__day + , subq_9.third_hop_ds__week + , subq_9.third_hop_ds__month + , subq_9.third_hop_ds__quarter + , subq_9.third_hop_ds__year + , subq_9.third_hop_ds__extract_year + , subq_9.third_hop_ds__extract_quarter + , subq_9.third_hop_ds__extract_month + , subq_9.third_hop_ds__extract_day + , subq_9.third_hop_ds__extract_dow + , subq_9.third_hop_ds__extract_doy + , subq_9.customer_third_hop_id__third_hop_ds__day + , subq_9.customer_third_hop_id__third_hop_ds__week + , subq_9.customer_third_hop_id__third_hop_ds__month + , subq_9.customer_third_hop_id__third_hop_ds__quarter + , subq_9.customer_third_hop_id__third_hop_ds__year + , subq_9.customer_third_hop_id__third_hop_ds__extract_year + , subq_9.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_9.customer_third_hop_id__third_hop_ds__extract_month + , subq_9.customer_third_hop_id__third_hop_ds__extract_day + , subq_9.customer_third_hop_id__third_hop_ds__extract_dow + , subq_9.customer_third_hop_id__third_hop_ds__extract_doy + , subq_9.third_hop_ds__day AS metric_time__day + , subq_9.third_hop_ds__week AS metric_time__week + , subq_9.third_hop_ds__month AS metric_time__month + , subq_9.third_hop_ds__quarter AS metric_time__quarter + , subq_9.third_hop_ds__year AS metric_time__year + , subq_9.third_hop_ds__extract_year AS metric_time__extract_year + , subq_9.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_9.third_hop_ds__extract_month AS metric_time__extract_month + , subq_9.third_hop_ds__extract_day AS metric_time__extract_day + , subq_9.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_9.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_9.customer_third_hop_id + , subq_9.value + , subq_9.customer_third_hop_id__value + , subq_9.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_19.customer_id__customer_third_hop_id + , subq_19.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , SUM(subq_17.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_15.customer_id__customer_third_hop_id + , subq_15.customer_id__country + , subq_15.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_14.customer_id__customer_third_hop_id + , subq_14.customer_id__country + , subq_14.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_13.acquired_ds__day + , subq_13.acquired_ds__week + , subq_13.acquired_ds__month + , subq_13.acquired_ds__quarter + , subq_13.acquired_ds__year + , subq_13.acquired_ds__extract_year + , subq_13.acquired_ds__extract_quarter + , subq_13.acquired_ds__extract_month + , subq_13.acquired_ds__extract_day + , subq_13.acquired_ds__extract_dow + , subq_13.acquired_ds__extract_doy + , subq_13.customer_id__acquired_ds__day + , subq_13.customer_id__acquired_ds__week + , subq_13.customer_id__acquired_ds__month + , subq_13.customer_id__acquired_ds__quarter + , subq_13.customer_id__acquired_ds__year + , subq_13.customer_id__acquired_ds__extract_year + , subq_13.customer_id__acquired_ds__extract_quarter + , subq_13.customer_id__acquired_ds__extract_month + , subq_13.customer_id__acquired_ds__extract_day + , subq_13.customer_id__acquired_ds__extract_dow + , subq_13.customer_id__acquired_ds__extract_doy + , subq_13.customer_third_hop_id__acquired_ds__day + , subq_13.customer_third_hop_id__acquired_ds__week + , subq_13.customer_third_hop_id__acquired_ds__month + , subq_13.customer_third_hop_id__acquired_ds__quarter + , subq_13.customer_third_hop_id__acquired_ds__year + , subq_13.customer_third_hop_id__acquired_ds__extract_year + , subq_13.customer_third_hop_id__acquired_ds__extract_quarter + , subq_13.customer_third_hop_id__acquired_ds__extract_month + , subq_13.customer_third_hop_id__acquired_ds__extract_day + , subq_13.customer_third_hop_id__acquired_ds__extract_dow + , subq_13.customer_third_hop_id__acquired_ds__extract_doy + , subq_13.metric_time__day + , subq_13.metric_time__week + , subq_13.metric_time__month + , subq_13.metric_time__quarter + , subq_13.metric_time__year + , subq_13.metric_time__extract_year + , subq_13.metric_time__extract_quarter + , subq_13.metric_time__extract_month + , subq_13.metric_time__extract_day + , subq_13.metric_time__extract_dow + , subq_13.metric_time__extract_doy + , subq_13.customer_id + , subq_13.customer_third_hop_id + , subq_13.customer_id__customer_third_hop_id + , subq_13.customer_third_hop_id__customer_id + , subq_13.country + , subq_13.customer_id__country + , subq_13.customer_third_hop_id__country + , subq_13.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_12.acquired_ds__day + , subq_12.acquired_ds__week + , subq_12.acquired_ds__month + , subq_12.acquired_ds__quarter + , subq_12.acquired_ds__year + , subq_12.acquired_ds__extract_year + , subq_12.acquired_ds__extract_quarter + , subq_12.acquired_ds__extract_month + , subq_12.acquired_ds__extract_day + , subq_12.acquired_ds__extract_dow + , subq_12.acquired_ds__extract_doy + , subq_12.customer_id__acquired_ds__day + , subq_12.customer_id__acquired_ds__week + , subq_12.customer_id__acquired_ds__month + , subq_12.customer_id__acquired_ds__quarter + , subq_12.customer_id__acquired_ds__year + , subq_12.customer_id__acquired_ds__extract_year + , subq_12.customer_id__acquired_ds__extract_quarter + , subq_12.customer_id__acquired_ds__extract_month + , subq_12.customer_id__acquired_ds__extract_day + , subq_12.customer_id__acquired_ds__extract_dow + , subq_12.customer_id__acquired_ds__extract_doy + , subq_12.customer_third_hop_id__acquired_ds__day + , subq_12.customer_third_hop_id__acquired_ds__week + , subq_12.customer_third_hop_id__acquired_ds__month + , subq_12.customer_third_hop_id__acquired_ds__quarter + , subq_12.customer_third_hop_id__acquired_ds__year + , subq_12.customer_third_hop_id__acquired_ds__extract_year + , subq_12.customer_third_hop_id__acquired_ds__extract_quarter + , subq_12.customer_third_hop_id__acquired_ds__extract_month + , subq_12.customer_third_hop_id__acquired_ds__extract_day + , subq_12.customer_third_hop_id__acquired_ds__extract_dow + , subq_12.customer_third_hop_id__acquired_ds__extract_doy + , subq_12.acquired_ds__day AS metric_time__day + , subq_12.acquired_ds__week AS metric_time__week + , subq_12.acquired_ds__month AS metric_time__month + , subq_12.acquired_ds__quarter AS metric_time__quarter + , subq_12.acquired_ds__year AS metric_time__year + , subq_12.acquired_ds__extract_year AS metric_time__extract_year + , subq_12.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_12.acquired_ds__extract_month AS metric_time__extract_month + , subq_12.acquired_ds__extract_day AS metric_time__extract_day + , subq_12.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_12.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_12.customer_id + , subq_12.customer_third_hop_id + , subq_12.customer_id__customer_third_hop_id + , subq_12.customer_third_hop_id__customer_id + , subq_12.country + , subq_12.customer_id__country + , subq_12.customer_third_hop_id__country + , subq_12.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_12 + ) subq_13 + WHERE customer_id__country = 'paraguay' + ) subq_14 + ) subq_15 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_16 + ) subq_17 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_17.customer_id__customer_third_hop_id + ) subq_18 + ) subq_19 + ) subq_20 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_11.customer_third_hop_id = subq_20.customer_id__customer_third_hop_id + ) subq_21 + ) subq_22 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_23 + ) subq_24 +) subq_25 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..4af49531fb 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_37.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_30 + WHERE customer_id__country = 'paraguay' + ) subq_32 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_37 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_37.customer_id__customer_third_hop_id +) subq_39 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0.sql index 6a27e35c22..7e727a5e96 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_25.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_24.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_23.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_22.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_22.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_21.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_21.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_11.customer_third_hop_id AS customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_11.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_10.customer_third_hop_id + , subq_10.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_9.third_hop_ds__day + , subq_9.third_hop_ds__week + , subq_9.third_hop_ds__month + , subq_9.third_hop_ds__quarter + , subq_9.third_hop_ds__year + , subq_9.third_hop_ds__extract_year + , subq_9.third_hop_ds__extract_quarter + , subq_9.third_hop_ds__extract_month + , subq_9.third_hop_ds__extract_day + , subq_9.third_hop_ds__extract_dow + , subq_9.third_hop_ds__extract_doy + , subq_9.customer_third_hop_id__third_hop_ds__day + , subq_9.customer_third_hop_id__third_hop_ds__week + , subq_9.customer_third_hop_id__third_hop_ds__month + , subq_9.customer_third_hop_id__third_hop_ds__quarter + , subq_9.customer_third_hop_id__third_hop_ds__year + , subq_9.customer_third_hop_id__third_hop_ds__extract_year + , subq_9.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_9.customer_third_hop_id__third_hop_ds__extract_month + , subq_9.customer_third_hop_id__third_hop_ds__extract_day + , subq_9.customer_third_hop_id__third_hop_ds__extract_dow + , subq_9.customer_third_hop_id__third_hop_ds__extract_doy + , subq_9.third_hop_ds__day AS metric_time__day + , subq_9.third_hop_ds__week AS metric_time__week + , subq_9.third_hop_ds__month AS metric_time__month + , subq_9.third_hop_ds__quarter AS metric_time__quarter + , subq_9.third_hop_ds__year AS metric_time__year + , subq_9.third_hop_ds__extract_year AS metric_time__extract_year + , subq_9.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_9.third_hop_ds__extract_month AS metric_time__extract_month + , subq_9.third_hop_ds__extract_day AS metric_time__extract_day + , subq_9.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_9.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_9.customer_third_hop_id + , subq_9.value + , subq_9.customer_third_hop_id__value + , subq_9.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_19.customer_id__customer_third_hop_id + , subq_19.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , SUM(subq_17.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_15.customer_id__customer_third_hop_id + , subq_15.customer_id__country + , subq_15.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_14.customer_id__customer_third_hop_id + , subq_14.customer_id__country + , subq_14.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_13.acquired_ds__day + , subq_13.acquired_ds__week + , subq_13.acquired_ds__month + , subq_13.acquired_ds__quarter + , subq_13.acquired_ds__year + , subq_13.acquired_ds__extract_year + , subq_13.acquired_ds__extract_quarter + , subq_13.acquired_ds__extract_month + , subq_13.acquired_ds__extract_day + , subq_13.acquired_ds__extract_dow + , subq_13.acquired_ds__extract_doy + , subq_13.customer_id__acquired_ds__day + , subq_13.customer_id__acquired_ds__week + , subq_13.customer_id__acquired_ds__month + , subq_13.customer_id__acquired_ds__quarter + , subq_13.customer_id__acquired_ds__year + , subq_13.customer_id__acquired_ds__extract_year + , subq_13.customer_id__acquired_ds__extract_quarter + , subq_13.customer_id__acquired_ds__extract_month + , subq_13.customer_id__acquired_ds__extract_day + , subq_13.customer_id__acquired_ds__extract_dow + , subq_13.customer_id__acquired_ds__extract_doy + , subq_13.customer_third_hop_id__acquired_ds__day + , subq_13.customer_third_hop_id__acquired_ds__week + , subq_13.customer_third_hop_id__acquired_ds__month + , subq_13.customer_third_hop_id__acquired_ds__quarter + , subq_13.customer_third_hop_id__acquired_ds__year + , subq_13.customer_third_hop_id__acquired_ds__extract_year + , subq_13.customer_third_hop_id__acquired_ds__extract_quarter + , subq_13.customer_third_hop_id__acquired_ds__extract_month + , subq_13.customer_third_hop_id__acquired_ds__extract_day + , subq_13.customer_third_hop_id__acquired_ds__extract_dow + , subq_13.customer_third_hop_id__acquired_ds__extract_doy + , subq_13.metric_time__day + , subq_13.metric_time__week + , subq_13.metric_time__month + , subq_13.metric_time__quarter + , subq_13.metric_time__year + , subq_13.metric_time__extract_year + , subq_13.metric_time__extract_quarter + , subq_13.metric_time__extract_month + , subq_13.metric_time__extract_day + , subq_13.metric_time__extract_dow + , subq_13.metric_time__extract_doy + , subq_13.customer_id + , subq_13.customer_third_hop_id + , subq_13.customer_id__customer_third_hop_id + , subq_13.customer_third_hop_id__customer_id + , subq_13.country + , subq_13.customer_id__country + , subq_13.customer_third_hop_id__country + , subq_13.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_12.acquired_ds__day + , subq_12.acquired_ds__week + , subq_12.acquired_ds__month + , subq_12.acquired_ds__quarter + , subq_12.acquired_ds__year + , subq_12.acquired_ds__extract_year + , subq_12.acquired_ds__extract_quarter + , subq_12.acquired_ds__extract_month + , subq_12.acquired_ds__extract_day + , subq_12.acquired_ds__extract_dow + , subq_12.acquired_ds__extract_doy + , subq_12.customer_id__acquired_ds__day + , subq_12.customer_id__acquired_ds__week + , subq_12.customer_id__acquired_ds__month + , subq_12.customer_id__acquired_ds__quarter + , subq_12.customer_id__acquired_ds__year + , subq_12.customer_id__acquired_ds__extract_year + , subq_12.customer_id__acquired_ds__extract_quarter + , subq_12.customer_id__acquired_ds__extract_month + , subq_12.customer_id__acquired_ds__extract_day + , subq_12.customer_id__acquired_ds__extract_dow + , subq_12.customer_id__acquired_ds__extract_doy + , subq_12.customer_third_hop_id__acquired_ds__day + , subq_12.customer_third_hop_id__acquired_ds__week + , subq_12.customer_third_hop_id__acquired_ds__month + , subq_12.customer_third_hop_id__acquired_ds__quarter + , subq_12.customer_third_hop_id__acquired_ds__year + , subq_12.customer_third_hop_id__acquired_ds__extract_year + , subq_12.customer_third_hop_id__acquired_ds__extract_quarter + , subq_12.customer_third_hop_id__acquired_ds__extract_month + , subq_12.customer_third_hop_id__acquired_ds__extract_day + , subq_12.customer_third_hop_id__acquired_ds__extract_dow + , subq_12.customer_third_hop_id__acquired_ds__extract_doy + , subq_12.acquired_ds__day AS metric_time__day + , subq_12.acquired_ds__week AS metric_time__week + , subq_12.acquired_ds__month AS metric_time__month + , subq_12.acquired_ds__quarter AS metric_time__quarter + , subq_12.acquired_ds__year AS metric_time__year + , subq_12.acquired_ds__extract_year AS metric_time__extract_year + , subq_12.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_12.acquired_ds__extract_month AS metric_time__extract_month + , subq_12.acquired_ds__extract_day AS metric_time__extract_day + , subq_12.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_12.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_12.customer_id + , subq_12.customer_third_hop_id + , subq_12.customer_id__customer_third_hop_id + , subq_12.customer_third_hop_id__customer_id + , subq_12.country + , subq_12.customer_id__country + , subq_12.customer_third_hop_id__country + , subq_12.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_12 + ) subq_13 + WHERE customer_id__country = 'paraguay' + ) subq_14 + ) subq_15 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_16 + ) subq_17 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_17.customer_id__customer_third_hop_id + ) subq_18 + ) subq_19 + ) subq_20 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_11.customer_third_hop_id = subq_20.customer_id__customer_third_hop_id + ) subq_21 + ) subq_22 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_23 + ) subq_24 +) subq_25 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..4af49531fb 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Postgres/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_37.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_30 + WHERE customer_id__country = 'paraguay' + ) subq_32 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_37 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_37.customer_id__customer_third_hop_id +) subq_39 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0.sql index f881118554..10fba73707 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_25.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_24.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_23.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_22.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_22.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_21.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_21.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_11.customer_third_hop_id AS customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_11.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_10.customer_third_hop_id + , subq_10.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_9.third_hop_ds__day + , subq_9.third_hop_ds__week + , subq_9.third_hop_ds__month + , subq_9.third_hop_ds__quarter + , subq_9.third_hop_ds__year + , subq_9.third_hop_ds__extract_year + , subq_9.third_hop_ds__extract_quarter + , subq_9.third_hop_ds__extract_month + , subq_9.third_hop_ds__extract_day + , subq_9.third_hop_ds__extract_dow + , subq_9.third_hop_ds__extract_doy + , subq_9.customer_third_hop_id__third_hop_ds__day + , subq_9.customer_third_hop_id__third_hop_ds__week + , subq_9.customer_third_hop_id__third_hop_ds__month + , subq_9.customer_third_hop_id__third_hop_ds__quarter + , subq_9.customer_third_hop_id__third_hop_ds__year + , subq_9.customer_third_hop_id__third_hop_ds__extract_year + , subq_9.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_9.customer_third_hop_id__third_hop_ds__extract_month + , subq_9.customer_third_hop_id__third_hop_ds__extract_day + , subq_9.customer_third_hop_id__third_hop_ds__extract_dow + , subq_9.customer_third_hop_id__third_hop_ds__extract_doy + , subq_9.third_hop_ds__day AS metric_time__day + , subq_9.third_hop_ds__week AS metric_time__week + , subq_9.third_hop_ds__month AS metric_time__month + , subq_9.third_hop_ds__quarter AS metric_time__quarter + , subq_9.third_hop_ds__year AS metric_time__year + , subq_9.third_hop_ds__extract_year AS metric_time__extract_year + , subq_9.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_9.third_hop_ds__extract_month AS metric_time__extract_month + , subq_9.third_hop_ds__extract_day AS metric_time__extract_day + , subq_9.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_9.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_9.customer_third_hop_id + , subq_9.value + , subq_9.customer_third_hop_id__value + , subq_9.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_19.customer_id__customer_third_hop_id + , subq_19.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , SUM(subq_17.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_15.customer_id__customer_third_hop_id + , subq_15.customer_id__country + , subq_15.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_14.customer_id__customer_third_hop_id + , subq_14.customer_id__country + , subq_14.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_13.acquired_ds__day + , subq_13.acquired_ds__week + , subq_13.acquired_ds__month + , subq_13.acquired_ds__quarter + , subq_13.acquired_ds__year + , subq_13.acquired_ds__extract_year + , subq_13.acquired_ds__extract_quarter + , subq_13.acquired_ds__extract_month + , subq_13.acquired_ds__extract_day + , subq_13.acquired_ds__extract_dow + , subq_13.acquired_ds__extract_doy + , subq_13.customer_id__acquired_ds__day + , subq_13.customer_id__acquired_ds__week + , subq_13.customer_id__acquired_ds__month + , subq_13.customer_id__acquired_ds__quarter + , subq_13.customer_id__acquired_ds__year + , subq_13.customer_id__acquired_ds__extract_year + , subq_13.customer_id__acquired_ds__extract_quarter + , subq_13.customer_id__acquired_ds__extract_month + , subq_13.customer_id__acquired_ds__extract_day + , subq_13.customer_id__acquired_ds__extract_dow + , subq_13.customer_id__acquired_ds__extract_doy + , subq_13.customer_third_hop_id__acquired_ds__day + , subq_13.customer_third_hop_id__acquired_ds__week + , subq_13.customer_third_hop_id__acquired_ds__month + , subq_13.customer_third_hop_id__acquired_ds__quarter + , subq_13.customer_third_hop_id__acquired_ds__year + , subq_13.customer_third_hop_id__acquired_ds__extract_year + , subq_13.customer_third_hop_id__acquired_ds__extract_quarter + , subq_13.customer_third_hop_id__acquired_ds__extract_month + , subq_13.customer_third_hop_id__acquired_ds__extract_day + , subq_13.customer_third_hop_id__acquired_ds__extract_dow + , subq_13.customer_third_hop_id__acquired_ds__extract_doy + , subq_13.metric_time__day + , subq_13.metric_time__week + , subq_13.metric_time__month + , subq_13.metric_time__quarter + , subq_13.metric_time__year + , subq_13.metric_time__extract_year + , subq_13.metric_time__extract_quarter + , subq_13.metric_time__extract_month + , subq_13.metric_time__extract_day + , subq_13.metric_time__extract_dow + , subq_13.metric_time__extract_doy + , subq_13.customer_id + , subq_13.customer_third_hop_id + , subq_13.customer_id__customer_third_hop_id + , subq_13.customer_third_hop_id__customer_id + , subq_13.country + , subq_13.customer_id__country + , subq_13.customer_third_hop_id__country + , subq_13.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_12.acquired_ds__day + , subq_12.acquired_ds__week + , subq_12.acquired_ds__month + , subq_12.acquired_ds__quarter + , subq_12.acquired_ds__year + , subq_12.acquired_ds__extract_year + , subq_12.acquired_ds__extract_quarter + , subq_12.acquired_ds__extract_month + , subq_12.acquired_ds__extract_day + , subq_12.acquired_ds__extract_dow + , subq_12.acquired_ds__extract_doy + , subq_12.customer_id__acquired_ds__day + , subq_12.customer_id__acquired_ds__week + , subq_12.customer_id__acquired_ds__month + , subq_12.customer_id__acquired_ds__quarter + , subq_12.customer_id__acquired_ds__year + , subq_12.customer_id__acquired_ds__extract_year + , subq_12.customer_id__acquired_ds__extract_quarter + , subq_12.customer_id__acquired_ds__extract_month + , subq_12.customer_id__acquired_ds__extract_day + , subq_12.customer_id__acquired_ds__extract_dow + , subq_12.customer_id__acquired_ds__extract_doy + , subq_12.customer_third_hop_id__acquired_ds__day + , subq_12.customer_third_hop_id__acquired_ds__week + , subq_12.customer_third_hop_id__acquired_ds__month + , subq_12.customer_third_hop_id__acquired_ds__quarter + , subq_12.customer_third_hop_id__acquired_ds__year + , subq_12.customer_third_hop_id__acquired_ds__extract_year + , subq_12.customer_third_hop_id__acquired_ds__extract_quarter + , subq_12.customer_third_hop_id__acquired_ds__extract_month + , subq_12.customer_third_hop_id__acquired_ds__extract_day + , subq_12.customer_third_hop_id__acquired_ds__extract_dow + , subq_12.customer_third_hop_id__acquired_ds__extract_doy + , subq_12.acquired_ds__day AS metric_time__day + , subq_12.acquired_ds__week AS metric_time__week + , subq_12.acquired_ds__month AS metric_time__month + , subq_12.acquired_ds__quarter AS metric_time__quarter + , subq_12.acquired_ds__year AS metric_time__year + , subq_12.acquired_ds__extract_year AS metric_time__extract_year + , subq_12.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_12.acquired_ds__extract_month AS metric_time__extract_month + , subq_12.acquired_ds__extract_day AS metric_time__extract_day + , subq_12.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_12.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_12.customer_id + , subq_12.customer_third_hop_id + , subq_12.customer_id__customer_third_hop_id + , subq_12.customer_third_hop_id__customer_id + , subq_12.country + , subq_12.customer_id__country + , subq_12.customer_third_hop_id__country + , subq_12.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , CASE WHEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) = 0 THEN EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) + 7 ELSE EXTRACT(dow FROM customer_other_data_src_22000.acquired_ds) END AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_12 + ) subq_13 + WHERE customer_id__country = 'paraguay' + ) subq_14 + ) subq_15 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_16 + ) subq_17 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_17.customer_id__customer_third_hop_id + ) subq_18 + ) subq_19 + ) subq_20 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_11.customer_third_hop_id = subq_20.customer_id__customer_third_hop_id + ) subq_21 + ) subq_22 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_23 + ) subq_24 +) subq_25 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..4af49531fb 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Redshift/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_37.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_30 + WHERE customer_id__country = 'paraguay' + ) subq_32 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_37 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_37.customer_id__customer_third_hop_id +) subq_39 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0.sql index 9cebbd1f96..fb72540d6e 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_25.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_24.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_23.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_22.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_22.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_21.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_21.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_11.customer_third_hop_id AS customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_11.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_10.customer_third_hop_id + , subq_10.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_9.third_hop_ds__day + , subq_9.third_hop_ds__week + , subq_9.third_hop_ds__month + , subq_9.third_hop_ds__quarter + , subq_9.third_hop_ds__year + , subq_9.third_hop_ds__extract_year + , subq_9.third_hop_ds__extract_quarter + , subq_9.third_hop_ds__extract_month + , subq_9.third_hop_ds__extract_day + , subq_9.third_hop_ds__extract_dow + , subq_9.third_hop_ds__extract_doy + , subq_9.customer_third_hop_id__third_hop_ds__day + , subq_9.customer_third_hop_id__third_hop_ds__week + , subq_9.customer_third_hop_id__third_hop_ds__month + , subq_9.customer_third_hop_id__third_hop_ds__quarter + , subq_9.customer_third_hop_id__third_hop_ds__year + , subq_9.customer_third_hop_id__third_hop_ds__extract_year + , subq_9.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_9.customer_third_hop_id__third_hop_ds__extract_month + , subq_9.customer_third_hop_id__third_hop_ds__extract_day + , subq_9.customer_third_hop_id__third_hop_ds__extract_dow + , subq_9.customer_third_hop_id__third_hop_ds__extract_doy + , subq_9.third_hop_ds__day AS metric_time__day + , subq_9.third_hop_ds__week AS metric_time__week + , subq_9.third_hop_ds__month AS metric_time__month + , subq_9.third_hop_ds__quarter AS metric_time__quarter + , subq_9.third_hop_ds__year AS metric_time__year + , subq_9.third_hop_ds__extract_year AS metric_time__extract_year + , subq_9.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_9.third_hop_ds__extract_month AS metric_time__extract_month + , subq_9.third_hop_ds__extract_day AS metric_time__extract_day + , subq_9.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_9.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_9.customer_third_hop_id + , subq_9.value + , subq_9.customer_third_hop_id__value + , subq_9.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_19.customer_id__customer_third_hop_id + , subq_19.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , SUM(subq_17.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_15.customer_id__customer_third_hop_id + , subq_15.customer_id__country + , subq_15.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_14.customer_id__customer_third_hop_id + , subq_14.customer_id__country + , subq_14.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_13.acquired_ds__day + , subq_13.acquired_ds__week + , subq_13.acquired_ds__month + , subq_13.acquired_ds__quarter + , subq_13.acquired_ds__year + , subq_13.acquired_ds__extract_year + , subq_13.acquired_ds__extract_quarter + , subq_13.acquired_ds__extract_month + , subq_13.acquired_ds__extract_day + , subq_13.acquired_ds__extract_dow + , subq_13.acquired_ds__extract_doy + , subq_13.customer_id__acquired_ds__day + , subq_13.customer_id__acquired_ds__week + , subq_13.customer_id__acquired_ds__month + , subq_13.customer_id__acquired_ds__quarter + , subq_13.customer_id__acquired_ds__year + , subq_13.customer_id__acquired_ds__extract_year + , subq_13.customer_id__acquired_ds__extract_quarter + , subq_13.customer_id__acquired_ds__extract_month + , subq_13.customer_id__acquired_ds__extract_day + , subq_13.customer_id__acquired_ds__extract_dow + , subq_13.customer_id__acquired_ds__extract_doy + , subq_13.customer_third_hop_id__acquired_ds__day + , subq_13.customer_third_hop_id__acquired_ds__week + , subq_13.customer_third_hop_id__acquired_ds__month + , subq_13.customer_third_hop_id__acquired_ds__quarter + , subq_13.customer_third_hop_id__acquired_ds__year + , subq_13.customer_third_hop_id__acquired_ds__extract_year + , subq_13.customer_third_hop_id__acquired_ds__extract_quarter + , subq_13.customer_third_hop_id__acquired_ds__extract_month + , subq_13.customer_third_hop_id__acquired_ds__extract_day + , subq_13.customer_third_hop_id__acquired_ds__extract_dow + , subq_13.customer_third_hop_id__acquired_ds__extract_doy + , subq_13.metric_time__day + , subq_13.metric_time__week + , subq_13.metric_time__month + , subq_13.metric_time__quarter + , subq_13.metric_time__year + , subq_13.metric_time__extract_year + , subq_13.metric_time__extract_quarter + , subq_13.metric_time__extract_month + , subq_13.metric_time__extract_day + , subq_13.metric_time__extract_dow + , subq_13.metric_time__extract_doy + , subq_13.customer_id + , subq_13.customer_third_hop_id + , subq_13.customer_id__customer_third_hop_id + , subq_13.customer_third_hop_id__customer_id + , subq_13.country + , subq_13.customer_id__country + , subq_13.customer_third_hop_id__country + , subq_13.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_12.acquired_ds__day + , subq_12.acquired_ds__week + , subq_12.acquired_ds__month + , subq_12.acquired_ds__quarter + , subq_12.acquired_ds__year + , subq_12.acquired_ds__extract_year + , subq_12.acquired_ds__extract_quarter + , subq_12.acquired_ds__extract_month + , subq_12.acquired_ds__extract_day + , subq_12.acquired_ds__extract_dow + , subq_12.acquired_ds__extract_doy + , subq_12.customer_id__acquired_ds__day + , subq_12.customer_id__acquired_ds__week + , subq_12.customer_id__acquired_ds__month + , subq_12.customer_id__acquired_ds__quarter + , subq_12.customer_id__acquired_ds__year + , subq_12.customer_id__acquired_ds__extract_year + , subq_12.customer_id__acquired_ds__extract_quarter + , subq_12.customer_id__acquired_ds__extract_month + , subq_12.customer_id__acquired_ds__extract_day + , subq_12.customer_id__acquired_ds__extract_dow + , subq_12.customer_id__acquired_ds__extract_doy + , subq_12.customer_third_hop_id__acquired_ds__day + , subq_12.customer_third_hop_id__acquired_ds__week + , subq_12.customer_third_hop_id__acquired_ds__month + , subq_12.customer_third_hop_id__acquired_ds__quarter + , subq_12.customer_third_hop_id__acquired_ds__year + , subq_12.customer_third_hop_id__acquired_ds__extract_year + , subq_12.customer_third_hop_id__acquired_ds__extract_quarter + , subq_12.customer_third_hop_id__acquired_ds__extract_month + , subq_12.customer_third_hop_id__acquired_ds__extract_day + , subq_12.customer_third_hop_id__acquired_ds__extract_dow + , subq_12.customer_third_hop_id__acquired_ds__extract_doy + , subq_12.acquired_ds__day AS metric_time__day + , subq_12.acquired_ds__week AS metric_time__week + , subq_12.acquired_ds__month AS metric_time__month + , subq_12.acquired_ds__quarter AS metric_time__quarter + , subq_12.acquired_ds__year AS metric_time__year + , subq_12.acquired_ds__extract_year AS metric_time__extract_year + , subq_12.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_12.acquired_ds__extract_month AS metric_time__extract_month + , subq_12.acquired_ds__extract_day AS metric_time__extract_day + , subq_12.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_12.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_12.customer_id + , subq_12.customer_third_hop_id + , subq_12.customer_id__customer_third_hop_id + , subq_12.customer_third_hop_id__customer_id + , subq_12.country + , subq_12.customer_id__country + , subq_12.customer_third_hop_id__country + , subq_12.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(dayofweekiso FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_12 + ) subq_13 + WHERE customer_id__country = 'paraguay' + ) subq_14 + ) subq_15 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_16 + ) subq_17 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_17.customer_id__customer_third_hop_id + ) subq_18 + ) subq_19 + ) subq_20 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_11.customer_third_hop_id = subq_20.customer_id__customer_third_hop_id + ) subq_21 + ) subq_22 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_23 + ) subq_24 +) subq_25 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..4af49531fb 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Snowflake/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_37.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_30 + WHERE customer_id__country = 'paraguay' + ) subq_32 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_37 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_37.customer_id__customer_third_hop_id +) subq_39 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0.sql index 12899f47dc..5938f67a2e 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0.sql @@ -1,76 +1,76 @@ -- Compute Metrics via Expressions SELECT - subq_21.third_hop_count + subq_25.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_20.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_24.third_hop_count) AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count',] SELECT - subq_19.third_hop_count + subq_23.third_hop_count FROM ( -- Constrain Output with WHERE SELECT - subq_18.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_18.third_hop_count + subq_22.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_22.third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_17.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_17.third_hop_count + subq_21.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_21.third_hop_count FROM ( -- Join Standard Outputs SELECT - subq_8.customer_third_hop_id AS customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_16.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_8.third_hop_count AS third_hop_count + subq_11.customer_third_hop_id AS customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id + , subq_20.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + , subq_11.third_hop_count AS third_hop_count FROM ( -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_7.customer_third_hop_id - , subq_7.third_hop_count + subq_10.customer_third_hop_id + , subq_10.third_hop_count FROM ( -- Metric Time Dimension 'third_hop_ds' SELECT - subq_6.third_hop_ds__day - , subq_6.third_hop_ds__week - , subq_6.third_hop_ds__month - , subq_6.third_hop_ds__quarter - , subq_6.third_hop_ds__year - , subq_6.third_hop_ds__extract_year - , subq_6.third_hop_ds__extract_quarter - , subq_6.third_hop_ds__extract_month - , subq_6.third_hop_ds__extract_day - , subq_6.third_hop_ds__extract_dow - , subq_6.third_hop_ds__extract_doy - , subq_6.customer_third_hop_id__third_hop_ds__day - , subq_6.customer_third_hop_id__third_hop_ds__week - , subq_6.customer_third_hop_id__third_hop_ds__month - , subq_6.customer_third_hop_id__third_hop_ds__quarter - , subq_6.customer_third_hop_id__third_hop_ds__year - , subq_6.customer_third_hop_id__third_hop_ds__extract_year - , subq_6.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_6.customer_third_hop_id__third_hop_ds__extract_month - , subq_6.customer_third_hop_id__third_hop_ds__extract_day - , subq_6.customer_third_hop_id__third_hop_ds__extract_dow - , subq_6.customer_third_hop_id__third_hop_ds__extract_doy - , subq_6.third_hop_ds__day AS metric_time__day - , subq_6.third_hop_ds__week AS metric_time__week - , subq_6.third_hop_ds__month AS metric_time__month - , subq_6.third_hop_ds__quarter AS metric_time__quarter - , subq_6.third_hop_ds__year AS metric_time__year - , subq_6.third_hop_ds__extract_year AS metric_time__extract_year - , subq_6.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_6.third_hop_ds__extract_month AS metric_time__extract_month - , subq_6.third_hop_ds__extract_day AS metric_time__extract_day - , subq_6.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_6.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_6.customer_third_hop_id - , subq_6.value - , subq_6.customer_third_hop_id__value - , subq_6.third_hop_count + subq_9.third_hop_ds__day + , subq_9.third_hop_ds__week + , subq_9.third_hop_ds__month + , subq_9.third_hop_ds__quarter + , subq_9.third_hop_ds__year + , subq_9.third_hop_ds__extract_year + , subq_9.third_hop_ds__extract_quarter + , subq_9.third_hop_ds__extract_month + , subq_9.third_hop_ds__extract_day + , subq_9.third_hop_ds__extract_dow + , subq_9.third_hop_ds__extract_doy + , subq_9.customer_third_hop_id__third_hop_ds__day + , subq_9.customer_third_hop_id__third_hop_ds__week + , subq_9.customer_third_hop_id__third_hop_ds__month + , subq_9.customer_third_hop_id__third_hop_ds__quarter + , subq_9.customer_third_hop_id__third_hop_ds__year + , subq_9.customer_third_hop_id__third_hop_ds__extract_year + , subq_9.customer_third_hop_id__third_hop_ds__extract_quarter + , subq_9.customer_third_hop_id__third_hop_ds__extract_month + , subq_9.customer_third_hop_id__third_hop_ds__extract_day + , subq_9.customer_third_hop_id__third_hop_ds__extract_dow + , subq_9.customer_third_hop_id__third_hop_ds__extract_doy + , subq_9.third_hop_ds__day AS metric_time__day + , subq_9.third_hop_ds__week AS metric_time__week + , subq_9.third_hop_ds__month AS metric_time__month + , subq_9.third_hop_ds__quarter AS metric_time__quarter + , subq_9.third_hop_ds__year AS metric_time__year + , subq_9.third_hop_ds__extract_year AS metric_time__extract_year + , subq_9.third_hop_ds__extract_quarter AS metric_time__extract_quarter + , subq_9.third_hop_ds__extract_month AS metric_time__extract_month + , subq_9.third_hop_ds__extract_day AS metric_time__extract_day + , subq_9.third_hop_ds__extract_dow AS metric_time__extract_dow + , subq_9.third_hop_ds__extract_doy AS metric_time__extract_doy + , subq_9.customer_third_hop_id + , subq_9.value + , subq_9.customer_third_hop_id__value + , subq_9.third_hop_count FROM ( -- Read Elements From Semantic Model 'third_hop_table' SELECT @@ -101,157 +101,214 @@ FROM ( , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy , third_hop_table_src_22000.customer_third_hop_id FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_6 - ) subq_7 - ) subq_8 + ) subq_9 + ) subq_10 + ) subq_11 LEFT OUTER JOIN ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_15.customer_id__customer_third_hop_id - , subq_15.customer_id__customer_third_hop_id__paraguayan_customers + subq_19.customer_id__customer_third_hop_id + , subq_19.customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Compute Metrics via Expressions SELECT - subq_14.customer_id__customer_third_hop_id - , subq_14.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_18.customer_id__customer_third_hop_id + , subq_18.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Aggregate Measures SELECT - subq_13.customer_id__customer_third_hop_id - , SUM(subq_13.customers_with_other_data) AS customers_with_other_data + subq_17.customer_id__customer_third_hop_id + , SUM(subq_17.customers_with_other_data) AS customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_12.customer_id__customer_third_hop_id - , subq_12.customers_with_other_data + subq_16.customer_id__customer_third_hop_id + , subq_16.customers_with_other_data FROM ( -- Constrain Output with WHERE SELECT - subq_11.customer_id__customer_third_hop_id - , subq_11.customer_id__country - , subq_11.customers_with_other_data + subq_15.customer_id__customer_third_hop_id + , subq_15.customer_id__country + , subq_15.customers_with_other_data FROM ( -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_10.customer_id__customer_third_hop_id - , subq_10.customer_id__country - , subq_10.customers_with_other_data + subq_14.customer_id__customer_third_hop_id + , subq_14.customer_id__country + , subq_14.customers_with_other_data FROM ( - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.acquired_ds__day AS metric_time__day - , subq_9.acquired_ds__week AS metric_time__week - , subq_9.acquired_ds__month AS metric_time__month - , subq_9.acquired_ds__quarter AS metric_time__quarter - , subq_9.acquired_ds__year AS metric_time__year - , subq_9.acquired_ds__extract_year AS metric_time__extract_year - , subq_9.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_9.acquired_ds__extract_month AS metric_time__extract_month - , subq_9.acquired_ds__extract_day AS metric_time__extract_day - , subq_9.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_9.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - , subq_9.customers_with_other_data + subq_13.acquired_ds__day + , subq_13.acquired_ds__week + , subq_13.acquired_ds__month + , subq_13.acquired_ds__quarter + , subq_13.acquired_ds__year + , subq_13.acquired_ds__extract_year + , subq_13.acquired_ds__extract_quarter + , subq_13.acquired_ds__extract_month + , subq_13.acquired_ds__extract_day + , subq_13.acquired_ds__extract_dow + , subq_13.acquired_ds__extract_doy + , subq_13.customer_id__acquired_ds__day + , subq_13.customer_id__acquired_ds__week + , subq_13.customer_id__acquired_ds__month + , subq_13.customer_id__acquired_ds__quarter + , subq_13.customer_id__acquired_ds__year + , subq_13.customer_id__acquired_ds__extract_year + , subq_13.customer_id__acquired_ds__extract_quarter + , subq_13.customer_id__acquired_ds__extract_month + , subq_13.customer_id__acquired_ds__extract_day + , subq_13.customer_id__acquired_ds__extract_dow + , subq_13.customer_id__acquired_ds__extract_doy + , subq_13.customer_third_hop_id__acquired_ds__day + , subq_13.customer_third_hop_id__acquired_ds__week + , subq_13.customer_third_hop_id__acquired_ds__month + , subq_13.customer_third_hop_id__acquired_ds__quarter + , subq_13.customer_third_hop_id__acquired_ds__year + , subq_13.customer_third_hop_id__acquired_ds__extract_year + , subq_13.customer_third_hop_id__acquired_ds__extract_quarter + , subq_13.customer_third_hop_id__acquired_ds__extract_month + , subq_13.customer_third_hop_id__acquired_ds__extract_day + , subq_13.customer_third_hop_id__acquired_ds__extract_dow + , subq_13.customer_third_hop_id__acquired_ds__extract_doy + , subq_13.metric_time__day + , subq_13.metric_time__week + , subq_13.metric_time__month + , subq_13.metric_time__quarter + , subq_13.metric_time__year + , subq_13.metric_time__extract_year + , subq_13.metric_time__extract_quarter + , subq_13.metric_time__extract_month + , subq_13.metric_time__extract_day + , subq_13.metric_time__extract_dow + , subq_13.metric_time__extract_doy + , subq_13.customer_id + , subq_13.customer_third_hop_id + , subq_13.customer_id__customer_third_hop_id + , subq_13.customer_third_hop_id__customer_id + , subq_13.country + , subq_13.customer_id__country + , subq_13.customer_third_hop_id__country + , subq_13.customers_with_other_data FROM ( - -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_9 - ) subq_10 - ) subq_11 + subq_12.acquired_ds__day + , subq_12.acquired_ds__week + , subq_12.acquired_ds__month + , subq_12.acquired_ds__quarter + , subq_12.acquired_ds__year + , subq_12.acquired_ds__extract_year + , subq_12.acquired_ds__extract_quarter + , subq_12.acquired_ds__extract_month + , subq_12.acquired_ds__extract_day + , subq_12.acquired_ds__extract_dow + , subq_12.acquired_ds__extract_doy + , subq_12.customer_id__acquired_ds__day + , subq_12.customer_id__acquired_ds__week + , subq_12.customer_id__acquired_ds__month + , subq_12.customer_id__acquired_ds__quarter + , subq_12.customer_id__acquired_ds__year + , subq_12.customer_id__acquired_ds__extract_year + , subq_12.customer_id__acquired_ds__extract_quarter + , subq_12.customer_id__acquired_ds__extract_month + , subq_12.customer_id__acquired_ds__extract_day + , subq_12.customer_id__acquired_ds__extract_dow + , subq_12.customer_id__acquired_ds__extract_doy + , subq_12.customer_third_hop_id__acquired_ds__day + , subq_12.customer_third_hop_id__acquired_ds__week + , subq_12.customer_third_hop_id__acquired_ds__month + , subq_12.customer_third_hop_id__acquired_ds__quarter + , subq_12.customer_third_hop_id__acquired_ds__year + , subq_12.customer_third_hop_id__acquired_ds__extract_year + , subq_12.customer_third_hop_id__acquired_ds__extract_quarter + , subq_12.customer_third_hop_id__acquired_ds__extract_month + , subq_12.customer_third_hop_id__acquired_ds__extract_day + , subq_12.customer_third_hop_id__acquired_ds__extract_dow + , subq_12.customer_third_hop_id__acquired_ds__extract_doy + , subq_12.acquired_ds__day AS metric_time__day + , subq_12.acquired_ds__week AS metric_time__week + , subq_12.acquired_ds__month AS metric_time__month + , subq_12.acquired_ds__quarter AS metric_time__quarter + , subq_12.acquired_ds__year AS metric_time__year + , subq_12.acquired_ds__extract_year AS metric_time__extract_year + , subq_12.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_12.acquired_ds__extract_month AS metric_time__extract_month + , subq_12.acquired_ds__extract_day AS metric_time__extract_day + , subq_12.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_12.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_12.customer_id + , subq_12.customer_third_hop_id + , subq_12.customer_id__customer_third_hop_id + , subq_12.customer_third_hop_id__customer_id + , subq_12.country + , subq_12.customer_id__country + , subq_12.customer_third_hop_id__country + , subq_12.customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + SELECT + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_12 + ) subq_13 + WHERE customer_id__country = 'paraguay' + ) subq_14 + ) subq_15 WHERE customer_id__country = 'paraguay' - ) subq_12 - ) subq_13 + ) subq_16 + ) subq_17 GROUP BY - subq_13.customer_id__customer_third_hop_id - ) subq_14 - ) subq_15 - ) subq_16 + subq_17.customer_id__customer_third_hop_id + ) subq_18 + ) subq_19 + ) subq_20 ON - subq_8.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id - ) subq_17 - ) subq_18 + subq_11.customer_third_hop_id = subq_20.customer_id__customer_third_hop_id + ) subq_21 + ) subq_22 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_19 - ) subq_20 -) subq_21 + ) subq_23 + ) subq_24 +) subq_25 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0_optimized.sql index 2ad52ec04c..4af49531fb 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/Trino/test_inner_query_single_hop__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_32.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers + subq_37.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( @@ -21,20 +21,28 @@ FROM ( customer_id__customer_third_hop_id , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - -- Metric Time Dimension 'acquired_ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - customer_third_hop_id AS customer_id__customer_third_hop_id - , country AS customer_id__country - , 1 AS customers_with_other_data - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_27 + customer_id__customer_third_hop_id + , customer_id__country + , customers_with_other_data + FROM ( + -- Read Elements From Semantic Model 'customer_other_data' + -- Metric Time Dimension 'acquired_ds' + SELECT + customer_third_hop_id AS customer_id__customer_third_hop_id + , country AS customer_id__country + , 1 AS customers_with_other_data + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_30 + WHERE customer_id__country = 'paraguay' + ) subq_32 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_32 + ) subq_37 ON - third_hop_table_src_22000.customer_third_hop_id = subq_32.customer_id__customer_third_hop_id -) subq_34 + third_hop_table_src_22000.customer_third_hop_id = subq_37.customer_id__customer_third_hop_id +) subq_39 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 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 9b3b0c4f8e..d79391ab01 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 @@ -1,130 +1,130 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] 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.created_at__day - , subq_8.created_at__week - , subq_8.created_at__month - , subq_8.created_at__quarter - , subq_8.created_at__year - , subq_8.created_at__extract_year - , subq_8.created_at__extract_quarter - , subq_8.created_at__extract_month - , subq_8.created_at__extract_day - , subq_8.created_at__extract_dow - , subq_8.created_at__extract_doy - , subq_8.listing__ds__day - , subq_8.listing__ds__week - , subq_8.listing__ds__month - , subq_8.listing__ds__quarter - , subq_8.listing__ds__year - , subq_8.listing__ds__extract_year - , subq_8.listing__ds__extract_quarter - , subq_8.listing__ds__extract_month - , subq_8.listing__ds__extract_day - , subq_8.listing__ds__extract_dow - , subq_8.listing__ds__extract_doy - , subq_8.listing__created_at__day - , subq_8.listing__created_at__week - , subq_8.listing__created_at__month - , subq_8.listing__created_at__quarter - , subq_8.listing__created_at__year - , subq_8.listing__created_at__extract_year - , subq_8.listing__created_at__extract_quarter - , subq_8.listing__created_at__extract_month - , subq_8.listing__created_at__extract_day - , subq_8.listing__created_at__extract_dow - , subq_8.listing__created_at__extract_doy - , subq_8.metric_time__day - , subq_8.listing - , subq_8.user - , subq_8.listing__user - , subq_8.country_latest - , subq_8.is_lux_latest - , subq_8.capacity_latest - , subq_8.listing__country_latest - , subq_8.listing__is_lux_latest - , subq_8.listing__capacity_latest - , subq_8.user__home_state_latest - , subq_8.listings - , subq_8.largest_listing - , subq_8.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.metric_time__day + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_2.ds__day AS ds__day - , subq_2.ds__week AS ds__week - , subq_2.ds__month AS ds__month - , subq_2.ds__quarter AS ds__quarter - , subq_2.ds__year AS ds__year - , subq_2.ds__extract_year AS ds__extract_year - , subq_2.ds__extract_quarter AS ds__extract_quarter - , subq_2.ds__extract_month AS ds__extract_month - , subq_2.ds__extract_day AS ds__extract_day - , subq_2.ds__extract_dow AS ds__extract_dow - , subq_2.ds__extract_doy AS ds__extract_doy - , subq_2.created_at__day AS created_at__day - , subq_2.created_at__week AS created_at__week - , subq_2.created_at__month AS created_at__month - , subq_2.created_at__quarter AS created_at__quarter - , subq_2.created_at__year AS created_at__year - , subq_2.created_at__extract_year AS created_at__extract_year - , subq_2.created_at__extract_quarter AS created_at__extract_quarter - , subq_2.created_at__extract_month AS created_at__extract_month - , subq_2.created_at__extract_day AS created_at__extract_day - , subq_2.created_at__extract_dow AS created_at__extract_dow - , subq_2.created_at__extract_doy AS created_at__extract_doy - , subq_2.listing__ds__day AS listing__ds__day - , subq_2.listing__ds__week AS listing__ds__week - , subq_2.listing__ds__month AS listing__ds__month - , subq_2.listing__ds__quarter AS listing__ds__quarter - , subq_2.listing__ds__year AS listing__ds__year - , subq_2.listing__ds__extract_year AS listing__ds__extract_year - , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_2.listing__ds__extract_month AS listing__ds__extract_month - , subq_2.listing__ds__extract_day AS listing__ds__extract_day - , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_2.listing__created_at__day AS listing__created_at__day - , subq_2.listing__created_at__week AS listing__created_at__week - , subq_2.listing__created_at__month AS listing__created_at__month - , subq_2.listing__created_at__quarter AS listing__created_at__quarter - , subq_2.listing__created_at__year AS listing__created_at__year - , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_5.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_2.user AS user - , subq_2.listing__user AS listing__user - , subq_2.country_latest AS country_latest - , subq_2.is_lux_latest AS is_lux_latest - , subq_2.capacity_latest AS capacity_latest - , subq_2.listing__country_latest AS listing__country_latest - , subq_2.listing__is_lux_latest AS listing__is_lux_latest - , subq_2.listing__capacity_latest AS listing__capacity_latest - , subq_7.home_state_latest AS user__home_state_latest - , subq_2.listings AS listings - , subq_2.largest_listing AS largest_listing - , subq_2.smallest_listing AS smallest_listing + 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.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.metric_time__day AS metric_time__day + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -185,36 +185,36 @@ 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_2 + ) subq_0 CROSS JOIN ( -- Pass Only Elements: ['metric_time__day',] SELECT - subq_4.metric_time__day + subq_2.metric_time__day FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy + subq_1.ds__day + , subq_1.ds__week + , subq_1.ds__month + , subq_1.ds__quarter + , subq_1.ds__year + , subq_1.ds__extract_year + , subq_1.ds__extract_quarter + , subq_1.ds__extract_month + , subq_1.ds__extract_day + , subq_1.ds__extract_dow + , subq_1.ds__extract_doy + , subq_1.ds__day AS metric_time__day + , subq_1.ds__week AS metric_time__week + , subq_1.ds__month AS metric_time__month + , subq_1.ds__quarter AS metric_time__quarter + , subq_1.ds__year AS metric_time__year + , subq_1.ds__extract_year AS metric_time__extract_year + , subq_1.ds__extract_quarter AS metric_time__extract_quarter + , subq_1.ds__extract_month AS metric_time__extract_month + , subq_1.ds__extract_day AS metric_time__extract_day + , subq_1.ds__extract_dow AS metric_time__extract_dow + , subq_1.ds__extract_doy AS metric_time__extract_doy FROM ( -- Time Spine SELECT @@ -230,14 +230,14 @@ FROM ( , IF(EXTRACT(dayofweek FROM time_spine_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM time_spine_src_28000.ds) - 1) AS ds__extract_dow , EXTRACT(dayofyear FROM time_spine_src_28000.ds) AS ds__extract_doy FROM ***************************.mf_time_spine time_spine_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_1 + ) subq_2 + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_6.user - , subq_6.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -267,13 +267,13 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_6 - ) subq_7 + ) subq_4 + ) subq_5 ON - subq_2.user = subq_7.user - ) subq_8 - WHERE subq_8.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' -) subq_9 + subq_0.user = subq_5.user + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' +) subq_7 GROUP BY metric_time__day , listing__is_lux_latest 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 7b375398ef..c158a74935 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 @@ -1,130 +1,130 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] 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.created_at__day - , subq_8.created_at__week - , subq_8.created_at__month - , subq_8.created_at__quarter - , subq_8.created_at__year - , subq_8.created_at__extract_year - , subq_8.created_at__extract_quarter - , subq_8.created_at__extract_month - , subq_8.created_at__extract_day - , subq_8.created_at__extract_dow - , subq_8.created_at__extract_doy - , subq_8.listing__ds__day - , subq_8.listing__ds__week - , subq_8.listing__ds__month - , subq_8.listing__ds__quarter - , subq_8.listing__ds__year - , subq_8.listing__ds__extract_year - , subq_8.listing__ds__extract_quarter - , subq_8.listing__ds__extract_month - , subq_8.listing__ds__extract_day - , subq_8.listing__ds__extract_dow - , subq_8.listing__ds__extract_doy - , subq_8.listing__created_at__day - , subq_8.listing__created_at__week - , subq_8.listing__created_at__month - , subq_8.listing__created_at__quarter - , subq_8.listing__created_at__year - , subq_8.listing__created_at__extract_year - , subq_8.listing__created_at__extract_quarter - , subq_8.listing__created_at__extract_month - , subq_8.listing__created_at__extract_day - , subq_8.listing__created_at__extract_dow - , subq_8.listing__created_at__extract_doy - , subq_8.metric_time__day - , subq_8.listing - , subq_8.user - , subq_8.listing__user - , subq_8.country_latest - , subq_8.is_lux_latest - , subq_8.capacity_latest - , subq_8.listing__country_latest - , subq_8.listing__is_lux_latest - , subq_8.listing__capacity_latest - , subq_8.user__home_state_latest - , subq_8.listings - , subq_8.largest_listing - , subq_8.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.metric_time__day + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_2.ds__day AS ds__day - , subq_2.ds__week AS ds__week - , subq_2.ds__month AS ds__month - , subq_2.ds__quarter AS ds__quarter - , subq_2.ds__year AS ds__year - , subq_2.ds__extract_year AS ds__extract_year - , subq_2.ds__extract_quarter AS ds__extract_quarter - , subq_2.ds__extract_month AS ds__extract_month - , subq_2.ds__extract_day AS ds__extract_day - , subq_2.ds__extract_dow AS ds__extract_dow - , subq_2.ds__extract_doy AS ds__extract_doy - , subq_2.created_at__day AS created_at__day - , subq_2.created_at__week AS created_at__week - , subq_2.created_at__month AS created_at__month - , subq_2.created_at__quarter AS created_at__quarter - , subq_2.created_at__year AS created_at__year - , subq_2.created_at__extract_year AS created_at__extract_year - , subq_2.created_at__extract_quarter AS created_at__extract_quarter - , subq_2.created_at__extract_month AS created_at__extract_month - , subq_2.created_at__extract_day AS created_at__extract_day - , subq_2.created_at__extract_dow AS created_at__extract_dow - , subq_2.created_at__extract_doy AS created_at__extract_doy - , subq_2.listing__ds__day AS listing__ds__day - , subq_2.listing__ds__week AS listing__ds__week - , subq_2.listing__ds__month AS listing__ds__month - , subq_2.listing__ds__quarter AS listing__ds__quarter - , subq_2.listing__ds__year AS listing__ds__year - , subq_2.listing__ds__extract_year AS listing__ds__extract_year - , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_2.listing__ds__extract_month AS listing__ds__extract_month - , subq_2.listing__ds__extract_day AS listing__ds__extract_day - , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_2.listing__created_at__day AS listing__created_at__day - , subq_2.listing__created_at__week AS listing__created_at__week - , subq_2.listing__created_at__month AS listing__created_at__month - , subq_2.listing__created_at__quarter AS listing__created_at__quarter - , subq_2.listing__created_at__year AS listing__created_at__year - , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_5.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_2.user AS user - , subq_2.listing__user AS listing__user - , subq_2.country_latest AS country_latest - , subq_2.is_lux_latest AS is_lux_latest - , subq_2.capacity_latest AS capacity_latest - , subq_2.listing__country_latest AS listing__country_latest - , subq_2.listing__is_lux_latest AS listing__is_lux_latest - , subq_2.listing__capacity_latest AS listing__capacity_latest - , subq_7.home_state_latest AS user__home_state_latest - , subq_2.listings AS listings - , subq_2.largest_listing AS largest_listing - , subq_2.smallest_listing AS smallest_listing + 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.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.metric_time__day AS metric_time__day + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -185,36 +185,36 @@ 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_2 + ) subq_0 CROSS JOIN ( -- Pass Only Elements: ['metric_time__day',] SELECT - subq_4.metric_time__day + subq_2.metric_time__day FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy + subq_1.ds__day + , subq_1.ds__week + , subq_1.ds__month + , subq_1.ds__quarter + , subq_1.ds__year + , subq_1.ds__extract_year + , subq_1.ds__extract_quarter + , subq_1.ds__extract_month + , subq_1.ds__extract_day + , subq_1.ds__extract_dow + , subq_1.ds__extract_doy + , subq_1.ds__day AS metric_time__day + , subq_1.ds__week AS metric_time__week + , subq_1.ds__month AS metric_time__month + , subq_1.ds__quarter AS metric_time__quarter + , subq_1.ds__year AS metric_time__year + , subq_1.ds__extract_year AS metric_time__extract_year + , subq_1.ds__extract_quarter AS metric_time__extract_quarter + , subq_1.ds__extract_month AS metric_time__extract_month + , subq_1.ds__extract_day AS metric_time__extract_day + , subq_1.ds__extract_dow AS metric_time__extract_dow + , subq_1.ds__extract_doy AS metric_time__extract_doy FROM ( -- Time Spine SELECT @@ -230,14 +230,14 @@ FROM ( , EXTRACT(DAYOFWEEK_ISO FROM time_spine_src_28000.ds) AS ds__extract_dow , EXTRACT(doy FROM time_spine_src_28000.ds) AS ds__extract_doy FROM ***************************.mf_time_spine time_spine_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_1 + ) subq_2 + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_6.user - , subq_6.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -267,14 +267,14 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_6 - ) subq_7 + ) subq_4 + ) subq_5 ON - subq_2.user = subq_7.user - ) subq_8 - WHERE subq_8.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' -) subq_9 + subq_0.user = subq_5.user + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' +) subq_7 GROUP BY - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_dimensions_with_time_constraint__plan0.sql index df768a7cba..1e42a5d726 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_dimensions_with_time_constraint__plan0.sql @@ -1,130 +1,130 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] 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.created_at__day - , subq_8.created_at__week - , subq_8.created_at__month - , subq_8.created_at__quarter - , subq_8.created_at__year - , subq_8.created_at__extract_year - , subq_8.created_at__extract_quarter - , subq_8.created_at__extract_month - , subq_8.created_at__extract_day - , subq_8.created_at__extract_dow - , subq_8.created_at__extract_doy - , subq_8.listing__ds__day - , subq_8.listing__ds__week - , subq_8.listing__ds__month - , subq_8.listing__ds__quarter - , subq_8.listing__ds__year - , subq_8.listing__ds__extract_year - , subq_8.listing__ds__extract_quarter - , subq_8.listing__ds__extract_month - , subq_8.listing__ds__extract_day - , subq_8.listing__ds__extract_dow - , subq_8.listing__ds__extract_doy - , subq_8.listing__created_at__day - , subq_8.listing__created_at__week - , subq_8.listing__created_at__month - , subq_8.listing__created_at__quarter - , subq_8.listing__created_at__year - , subq_8.listing__created_at__extract_year - , subq_8.listing__created_at__extract_quarter - , subq_8.listing__created_at__extract_month - , subq_8.listing__created_at__extract_day - , subq_8.listing__created_at__extract_dow - , subq_8.listing__created_at__extract_doy - , subq_8.metric_time__day - , subq_8.listing - , subq_8.user - , subq_8.listing__user - , subq_8.country_latest - , subq_8.is_lux_latest - , subq_8.capacity_latest - , subq_8.listing__country_latest - , subq_8.listing__is_lux_latest - , subq_8.listing__capacity_latest - , subq_8.user__home_state_latest - , subq_8.listings - , subq_8.largest_listing - , subq_8.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.metric_time__day + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_2.ds__day AS ds__day - , subq_2.ds__week AS ds__week - , subq_2.ds__month AS ds__month - , subq_2.ds__quarter AS ds__quarter - , subq_2.ds__year AS ds__year - , subq_2.ds__extract_year AS ds__extract_year - , subq_2.ds__extract_quarter AS ds__extract_quarter - , subq_2.ds__extract_month AS ds__extract_month - , subq_2.ds__extract_day AS ds__extract_day - , subq_2.ds__extract_dow AS ds__extract_dow - , subq_2.ds__extract_doy AS ds__extract_doy - , subq_2.created_at__day AS created_at__day - , subq_2.created_at__week AS created_at__week - , subq_2.created_at__month AS created_at__month - , subq_2.created_at__quarter AS created_at__quarter - , subq_2.created_at__year AS created_at__year - , subq_2.created_at__extract_year AS created_at__extract_year - , subq_2.created_at__extract_quarter AS created_at__extract_quarter - , subq_2.created_at__extract_month AS created_at__extract_month - , subq_2.created_at__extract_day AS created_at__extract_day - , subq_2.created_at__extract_dow AS created_at__extract_dow - , subq_2.created_at__extract_doy AS created_at__extract_doy - , subq_2.listing__ds__day AS listing__ds__day - , subq_2.listing__ds__week AS listing__ds__week - , subq_2.listing__ds__month AS listing__ds__month - , subq_2.listing__ds__quarter AS listing__ds__quarter - , subq_2.listing__ds__year AS listing__ds__year - , subq_2.listing__ds__extract_year AS listing__ds__extract_year - , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_2.listing__ds__extract_month AS listing__ds__extract_month - , subq_2.listing__ds__extract_day AS listing__ds__extract_day - , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_2.listing__created_at__day AS listing__created_at__day - , subq_2.listing__created_at__week AS listing__created_at__week - , subq_2.listing__created_at__month AS listing__created_at__month - , subq_2.listing__created_at__quarter AS listing__created_at__quarter - , subq_2.listing__created_at__year AS listing__created_at__year - , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_5.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_2.user AS user - , subq_2.listing__user AS listing__user - , subq_2.country_latest AS country_latest - , subq_2.is_lux_latest AS is_lux_latest - , subq_2.capacity_latest AS capacity_latest - , subq_2.listing__country_latest AS listing__country_latest - , subq_2.listing__is_lux_latest AS listing__is_lux_latest - , subq_2.listing__capacity_latest AS listing__capacity_latest - , subq_7.home_state_latest AS user__home_state_latest - , subq_2.listings AS listings - , subq_2.largest_listing AS largest_listing - , subq_2.smallest_listing AS smallest_listing + 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.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.metric_time__day AS metric_time__day + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -185,36 +185,36 @@ 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_2 + ) subq_0 CROSS JOIN ( -- Pass Only Elements: ['metric_time__day',] SELECT - subq_4.metric_time__day + subq_2.metric_time__day FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy + subq_1.ds__day + , subq_1.ds__week + , subq_1.ds__month + , subq_1.ds__quarter + , subq_1.ds__year + , subq_1.ds__extract_year + , subq_1.ds__extract_quarter + , subq_1.ds__extract_month + , subq_1.ds__extract_day + , subq_1.ds__extract_dow + , subq_1.ds__extract_doy + , subq_1.ds__day AS metric_time__day + , subq_1.ds__week AS metric_time__week + , subq_1.ds__month AS metric_time__month + , subq_1.ds__quarter AS metric_time__quarter + , subq_1.ds__year AS metric_time__year + , subq_1.ds__extract_year AS metric_time__extract_year + , subq_1.ds__extract_quarter AS metric_time__extract_quarter + , subq_1.ds__extract_month AS metric_time__extract_month + , subq_1.ds__extract_day AS metric_time__extract_day + , subq_1.ds__extract_dow AS metric_time__extract_dow + , subq_1.ds__extract_doy AS metric_time__extract_doy FROM ( -- Time Spine SELECT @@ -230,14 +230,14 @@ FROM ( , EXTRACT(isodow FROM time_spine_src_28000.ds) AS ds__extract_dow , EXTRACT(doy FROM time_spine_src_28000.ds) AS ds__extract_doy FROM ***************************.mf_time_spine time_spine_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_1 + ) subq_2 + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_6.user - , subq_6.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -267,14 +267,14 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_6 - ) subq_7 + ) subq_4 + ) subq_5 ON - subq_2.user = subq_7.user - ) subq_8 - WHERE subq_8.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' -) subq_9 + subq_0.user = subq_5.user + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' +) subq_7 GROUP BY - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__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 df768a7cba..1e42a5d726 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 @@ -1,130 +1,130 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] 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.created_at__day - , subq_8.created_at__week - , subq_8.created_at__month - , subq_8.created_at__quarter - , subq_8.created_at__year - , subq_8.created_at__extract_year - , subq_8.created_at__extract_quarter - , subq_8.created_at__extract_month - , subq_8.created_at__extract_day - , subq_8.created_at__extract_dow - , subq_8.created_at__extract_doy - , subq_8.listing__ds__day - , subq_8.listing__ds__week - , subq_8.listing__ds__month - , subq_8.listing__ds__quarter - , subq_8.listing__ds__year - , subq_8.listing__ds__extract_year - , subq_8.listing__ds__extract_quarter - , subq_8.listing__ds__extract_month - , subq_8.listing__ds__extract_day - , subq_8.listing__ds__extract_dow - , subq_8.listing__ds__extract_doy - , subq_8.listing__created_at__day - , subq_8.listing__created_at__week - , subq_8.listing__created_at__month - , subq_8.listing__created_at__quarter - , subq_8.listing__created_at__year - , subq_8.listing__created_at__extract_year - , subq_8.listing__created_at__extract_quarter - , subq_8.listing__created_at__extract_month - , subq_8.listing__created_at__extract_day - , subq_8.listing__created_at__extract_dow - , subq_8.listing__created_at__extract_doy - , subq_8.metric_time__day - , subq_8.listing - , subq_8.user - , subq_8.listing__user - , subq_8.country_latest - , subq_8.is_lux_latest - , subq_8.capacity_latest - , subq_8.listing__country_latest - , subq_8.listing__is_lux_latest - , subq_8.listing__capacity_latest - , subq_8.user__home_state_latest - , subq_8.listings - , subq_8.largest_listing - , subq_8.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.metric_time__day + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_2.ds__day AS ds__day - , subq_2.ds__week AS ds__week - , subq_2.ds__month AS ds__month - , subq_2.ds__quarter AS ds__quarter - , subq_2.ds__year AS ds__year - , subq_2.ds__extract_year AS ds__extract_year - , subq_2.ds__extract_quarter AS ds__extract_quarter - , subq_2.ds__extract_month AS ds__extract_month - , subq_2.ds__extract_day AS ds__extract_day - , subq_2.ds__extract_dow AS ds__extract_dow - , subq_2.ds__extract_doy AS ds__extract_doy - , subq_2.created_at__day AS created_at__day - , subq_2.created_at__week AS created_at__week - , subq_2.created_at__month AS created_at__month - , subq_2.created_at__quarter AS created_at__quarter - , subq_2.created_at__year AS created_at__year - , subq_2.created_at__extract_year AS created_at__extract_year - , subq_2.created_at__extract_quarter AS created_at__extract_quarter - , subq_2.created_at__extract_month AS created_at__extract_month - , subq_2.created_at__extract_day AS created_at__extract_day - , subq_2.created_at__extract_dow AS created_at__extract_dow - , subq_2.created_at__extract_doy AS created_at__extract_doy - , subq_2.listing__ds__day AS listing__ds__day - , subq_2.listing__ds__week AS listing__ds__week - , subq_2.listing__ds__month AS listing__ds__month - , subq_2.listing__ds__quarter AS listing__ds__quarter - , subq_2.listing__ds__year AS listing__ds__year - , subq_2.listing__ds__extract_year AS listing__ds__extract_year - , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_2.listing__ds__extract_month AS listing__ds__extract_month - , subq_2.listing__ds__extract_day AS listing__ds__extract_day - , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_2.listing__created_at__day AS listing__created_at__day - , subq_2.listing__created_at__week AS listing__created_at__week - , subq_2.listing__created_at__month AS listing__created_at__month - , subq_2.listing__created_at__quarter AS listing__created_at__quarter - , subq_2.listing__created_at__year AS listing__created_at__year - , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_5.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_2.user AS user - , subq_2.listing__user AS listing__user - , subq_2.country_latest AS country_latest - , subq_2.is_lux_latest AS is_lux_latest - , subq_2.capacity_latest AS capacity_latest - , subq_2.listing__country_latest AS listing__country_latest - , subq_2.listing__is_lux_latest AS listing__is_lux_latest - , subq_2.listing__capacity_latest AS listing__capacity_latest - , subq_7.home_state_latest AS user__home_state_latest - , subq_2.listings AS listings - , subq_2.largest_listing AS largest_listing - , subq_2.smallest_listing AS smallest_listing + 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.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.metric_time__day AS metric_time__day + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -185,36 +185,36 @@ 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_2 + ) subq_0 CROSS JOIN ( -- Pass Only Elements: ['metric_time__day',] SELECT - subq_4.metric_time__day + subq_2.metric_time__day FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy + subq_1.ds__day + , subq_1.ds__week + , subq_1.ds__month + , subq_1.ds__quarter + , subq_1.ds__year + , subq_1.ds__extract_year + , subq_1.ds__extract_quarter + , subq_1.ds__extract_month + , subq_1.ds__extract_day + , subq_1.ds__extract_dow + , subq_1.ds__extract_doy + , subq_1.ds__day AS metric_time__day + , subq_1.ds__week AS metric_time__week + , subq_1.ds__month AS metric_time__month + , subq_1.ds__quarter AS metric_time__quarter + , subq_1.ds__year AS metric_time__year + , subq_1.ds__extract_year AS metric_time__extract_year + , subq_1.ds__extract_quarter AS metric_time__extract_quarter + , subq_1.ds__extract_month AS metric_time__extract_month + , subq_1.ds__extract_day AS metric_time__extract_day + , subq_1.ds__extract_dow AS metric_time__extract_dow + , subq_1.ds__extract_doy AS metric_time__extract_doy FROM ( -- Time Spine SELECT @@ -230,14 +230,14 @@ FROM ( , EXTRACT(isodow FROM time_spine_src_28000.ds) AS ds__extract_dow , EXTRACT(doy FROM time_spine_src_28000.ds) AS ds__extract_doy FROM ***************************.mf_time_spine time_spine_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_1 + ) subq_2 + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_6.user - , subq_6.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -267,14 +267,14 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_6 - ) subq_7 + ) subq_4 + ) subq_5 ON - subq_2.user = subq_7.user - ) subq_8 - WHERE subq_8.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' -) subq_9 + subq_0.user = subq_5.user + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' +) subq_7 GROUP BY - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__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 547b977463..5d4572d904 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 @@ -1,130 +1,130 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] 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.created_at__day - , subq_8.created_at__week - , subq_8.created_at__month - , subq_8.created_at__quarter - , subq_8.created_at__year - , subq_8.created_at__extract_year - , subq_8.created_at__extract_quarter - , subq_8.created_at__extract_month - , subq_8.created_at__extract_day - , subq_8.created_at__extract_dow - , subq_8.created_at__extract_doy - , subq_8.listing__ds__day - , subq_8.listing__ds__week - , subq_8.listing__ds__month - , subq_8.listing__ds__quarter - , subq_8.listing__ds__year - , subq_8.listing__ds__extract_year - , subq_8.listing__ds__extract_quarter - , subq_8.listing__ds__extract_month - , subq_8.listing__ds__extract_day - , subq_8.listing__ds__extract_dow - , subq_8.listing__ds__extract_doy - , subq_8.listing__created_at__day - , subq_8.listing__created_at__week - , subq_8.listing__created_at__month - , subq_8.listing__created_at__quarter - , subq_8.listing__created_at__year - , subq_8.listing__created_at__extract_year - , subq_8.listing__created_at__extract_quarter - , subq_8.listing__created_at__extract_month - , subq_8.listing__created_at__extract_day - , subq_8.listing__created_at__extract_dow - , subq_8.listing__created_at__extract_doy - , subq_8.metric_time__day - , subq_8.listing - , subq_8.user - , subq_8.listing__user - , subq_8.country_latest - , subq_8.is_lux_latest - , subq_8.capacity_latest - , subq_8.listing__country_latest - , subq_8.listing__is_lux_latest - , subq_8.listing__capacity_latest - , subq_8.user__home_state_latest - , subq_8.listings - , subq_8.largest_listing - , subq_8.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.metric_time__day + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_2.ds__day AS ds__day - , subq_2.ds__week AS ds__week - , subq_2.ds__month AS ds__month - , subq_2.ds__quarter AS ds__quarter - , subq_2.ds__year AS ds__year - , subq_2.ds__extract_year AS ds__extract_year - , subq_2.ds__extract_quarter AS ds__extract_quarter - , subq_2.ds__extract_month AS ds__extract_month - , subq_2.ds__extract_day AS ds__extract_day - , subq_2.ds__extract_dow AS ds__extract_dow - , subq_2.ds__extract_doy AS ds__extract_doy - , subq_2.created_at__day AS created_at__day - , subq_2.created_at__week AS created_at__week - , subq_2.created_at__month AS created_at__month - , subq_2.created_at__quarter AS created_at__quarter - , subq_2.created_at__year AS created_at__year - , subq_2.created_at__extract_year AS created_at__extract_year - , subq_2.created_at__extract_quarter AS created_at__extract_quarter - , subq_2.created_at__extract_month AS created_at__extract_month - , subq_2.created_at__extract_day AS created_at__extract_day - , subq_2.created_at__extract_dow AS created_at__extract_dow - , subq_2.created_at__extract_doy AS created_at__extract_doy - , subq_2.listing__ds__day AS listing__ds__day - , subq_2.listing__ds__week AS listing__ds__week - , subq_2.listing__ds__month AS listing__ds__month - , subq_2.listing__ds__quarter AS listing__ds__quarter - , subq_2.listing__ds__year AS listing__ds__year - , subq_2.listing__ds__extract_year AS listing__ds__extract_year - , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_2.listing__ds__extract_month AS listing__ds__extract_month - , subq_2.listing__ds__extract_day AS listing__ds__extract_day - , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_2.listing__created_at__day AS listing__created_at__day - , subq_2.listing__created_at__week AS listing__created_at__week - , subq_2.listing__created_at__month AS listing__created_at__month - , subq_2.listing__created_at__quarter AS listing__created_at__quarter - , subq_2.listing__created_at__year AS listing__created_at__year - , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_5.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_2.user AS user - , subq_2.listing__user AS listing__user - , subq_2.country_latest AS country_latest - , subq_2.is_lux_latest AS is_lux_latest - , subq_2.capacity_latest AS capacity_latest - , subq_2.listing__country_latest AS listing__country_latest - , subq_2.listing__is_lux_latest AS listing__is_lux_latest - , subq_2.listing__capacity_latest AS listing__capacity_latest - , subq_7.home_state_latest AS user__home_state_latest - , subq_2.listings AS listings - , subq_2.largest_listing AS largest_listing - , subq_2.smallest_listing AS smallest_listing + 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.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.metric_time__day AS metric_time__day + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -185,36 +185,36 @@ 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_2 + ) subq_0 CROSS JOIN ( -- Pass Only Elements: ['metric_time__day',] SELECT - subq_4.metric_time__day + subq_2.metric_time__day FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy + subq_1.ds__day + , subq_1.ds__week + , subq_1.ds__month + , subq_1.ds__quarter + , subq_1.ds__year + , subq_1.ds__extract_year + , subq_1.ds__extract_quarter + , subq_1.ds__extract_month + , subq_1.ds__extract_day + , subq_1.ds__extract_dow + , subq_1.ds__extract_doy + , subq_1.ds__day AS metric_time__day + , subq_1.ds__week AS metric_time__week + , subq_1.ds__month AS metric_time__month + , subq_1.ds__quarter AS metric_time__quarter + , subq_1.ds__year AS metric_time__year + , subq_1.ds__extract_year AS metric_time__extract_year + , subq_1.ds__extract_quarter AS metric_time__extract_quarter + , subq_1.ds__extract_month AS metric_time__extract_month + , subq_1.ds__extract_day AS metric_time__extract_day + , subq_1.ds__extract_dow AS metric_time__extract_dow + , subq_1.ds__extract_doy AS metric_time__extract_doy FROM ( -- Time Spine SELECT @@ -230,14 +230,14 @@ FROM ( , CASE WHEN EXTRACT(dow FROM time_spine_src_28000.ds) = 0 THEN EXTRACT(dow FROM time_spine_src_28000.ds) + 7 ELSE EXTRACT(dow FROM time_spine_src_28000.ds) END AS ds__extract_dow , EXTRACT(doy FROM time_spine_src_28000.ds) AS ds__extract_doy FROM ***************************.mf_time_spine time_spine_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_1 + ) subq_2 + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_6.user - , subq_6.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -267,14 +267,14 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_6 - ) subq_7 + ) subq_4 + ) subq_5 ON - subq_2.user = subq_7.user - ) subq_8 - WHERE subq_8.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' -) subq_9 + subq_0.user = subq_5.user + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' +) subq_7 GROUP BY - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__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 0cb9d9f2d6..98667582a9 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 @@ -1,130 +1,130 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] 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.created_at__day - , subq_8.created_at__week - , subq_8.created_at__month - , subq_8.created_at__quarter - , subq_8.created_at__year - , subq_8.created_at__extract_year - , subq_8.created_at__extract_quarter - , subq_8.created_at__extract_month - , subq_8.created_at__extract_day - , subq_8.created_at__extract_dow - , subq_8.created_at__extract_doy - , subq_8.listing__ds__day - , subq_8.listing__ds__week - , subq_8.listing__ds__month - , subq_8.listing__ds__quarter - , subq_8.listing__ds__year - , subq_8.listing__ds__extract_year - , subq_8.listing__ds__extract_quarter - , subq_8.listing__ds__extract_month - , subq_8.listing__ds__extract_day - , subq_8.listing__ds__extract_dow - , subq_8.listing__ds__extract_doy - , subq_8.listing__created_at__day - , subq_8.listing__created_at__week - , subq_8.listing__created_at__month - , subq_8.listing__created_at__quarter - , subq_8.listing__created_at__year - , subq_8.listing__created_at__extract_year - , subq_8.listing__created_at__extract_quarter - , subq_8.listing__created_at__extract_month - , subq_8.listing__created_at__extract_day - , subq_8.listing__created_at__extract_dow - , subq_8.listing__created_at__extract_doy - , subq_8.metric_time__day - , subq_8.listing - , subq_8.user - , subq_8.listing__user - , subq_8.country_latest - , subq_8.is_lux_latest - , subq_8.capacity_latest - , subq_8.listing__country_latest - , subq_8.listing__is_lux_latest - , subq_8.listing__capacity_latest - , subq_8.user__home_state_latest - , subq_8.listings - , subq_8.largest_listing - , subq_8.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.metric_time__day + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_2.ds__day AS ds__day - , subq_2.ds__week AS ds__week - , subq_2.ds__month AS ds__month - , subq_2.ds__quarter AS ds__quarter - , subq_2.ds__year AS ds__year - , subq_2.ds__extract_year AS ds__extract_year - , subq_2.ds__extract_quarter AS ds__extract_quarter - , subq_2.ds__extract_month AS ds__extract_month - , subq_2.ds__extract_day AS ds__extract_day - , subq_2.ds__extract_dow AS ds__extract_dow - , subq_2.ds__extract_doy AS ds__extract_doy - , subq_2.created_at__day AS created_at__day - , subq_2.created_at__week AS created_at__week - , subq_2.created_at__month AS created_at__month - , subq_2.created_at__quarter AS created_at__quarter - , subq_2.created_at__year AS created_at__year - , subq_2.created_at__extract_year AS created_at__extract_year - , subq_2.created_at__extract_quarter AS created_at__extract_quarter - , subq_2.created_at__extract_month AS created_at__extract_month - , subq_2.created_at__extract_day AS created_at__extract_day - , subq_2.created_at__extract_dow AS created_at__extract_dow - , subq_2.created_at__extract_doy AS created_at__extract_doy - , subq_2.listing__ds__day AS listing__ds__day - , subq_2.listing__ds__week AS listing__ds__week - , subq_2.listing__ds__month AS listing__ds__month - , subq_2.listing__ds__quarter AS listing__ds__quarter - , subq_2.listing__ds__year AS listing__ds__year - , subq_2.listing__ds__extract_year AS listing__ds__extract_year - , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_2.listing__ds__extract_month AS listing__ds__extract_month - , subq_2.listing__ds__extract_day AS listing__ds__extract_day - , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_2.listing__created_at__day AS listing__created_at__day - , subq_2.listing__created_at__week AS listing__created_at__week - , subq_2.listing__created_at__month AS listing__created_at__month - , subq_2.listing__created_at__quarter AS listing__created_at__quarter - , subq_2.listing__created_at__year AS listing__created_at__year - , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_5.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_2.user AS user - , subq_2.listing__user AS listing__user - , subq_2.country_latest AS country_latest - , subq_2.is_lux_latest AS is_lux_latest - , subq_2.capacity_latest AS capacity_latest - , subq_2.listing__country_latest AS listing__country_latest - , subq_2.listing__is_lux_latest AS listing__is_lux_latest - , subq_2.listing__capacity_latest AS listing__capacity_latest - , subq_7.home_state_latest AS user__home_state_latest - , subq_2.listings AS listings - , subq_2.largest_listing AS largest_listing - , subq_2.smallest_listing AS smallest_listing + 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.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.metric_time__day AS metric_time__day + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -185,36 +185,36 @@ 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_2 + ) subq_0 CROSS JOIN ( -- Pass Only Elements: ['metric_time__day',] SELECT - subq_4.metric_time__day + subq_2.metric_time__day FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy + subq_1.ds__day + , subq_1.ds__week + , subq_1.ds__month + , subq_1.ds__quarter + , subq_1.ds__year + , subq_1.ds__extract_year + , subq_1.ds__extract_quarter + , subq_1.ds__extract_month + , subq_1.ds__extract_day + , subq_1.ds__extract_dow + , subq_1.ds__extract_doy + , subq_1.ds__day AS metric_time__day + , subq_1.ds__week AS metric_time__week + , subq_1.ds__month AS metric_time__month + , subq_1.ds__quarter AS metric_time__quarter + , subq_1.ds__year AS metric_time__year + , subq_1.ds__extract_year AS metric_time__extract_year + , subq_1.ds__extract_quarter AS metric_time__extract_quarter + , subq_1.ds__extract_month AS metric_time__extract_month + , subq_1.ds__extract_day AS metric_time__extract_day + , subq_1.ds__extract_dow AS metric_time__extract_dow + , subq_1.ds__extract_doy AS metric_time__extract_doy FROM ( -- Time Spine SELECT @@ -230,14 +230,14 @@ FROM ( , EXTRACT(dayofweekiso FROM time_spine_src_28000.ds) AS ds__extract_dow , EXTRACT(doy FROM time_spine_src_28000.ds) AS ds__extract_doy FROM ***************************.mf_time_spine time_spine_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_1 + ) subq_2 + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_6.user - , subq_6.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -267,14 +267,14 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_6 - ) subq_7 + ) subq_4 + ) subq_5 ON - subq_2.user = subq_7.user - ) subq_8 - WHERE subq_8.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' -) subq_9 + subq_0.user = subq_5.user + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' +) subq_7 GROUP BY - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__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 e5b54b564d..89ae3ebda3 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 @@ -1,130 +1,130 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest FROM ( -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] 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.created_at__day - , subq_8.created_at__week - , subq_8.created_at__month - , subq_8.created_at__quarter - , subq_8.created_at__year - , subq_8.created_at__extract_year - , subq_8.created_at__extract_quarter - , subq_8.created_at__extract_month - , subq_8.created_at__extract_day - , subq_8.created_at__extract_dow - , subq_8.created_at__extract_doy - , subq_8.listing__ds__day - , subq_8.listing__ds__week - , subq_8.listing__ds__month - , subq_8.listing__ds__quarter - , subq_8.listing__ds__year - , subq_8.listing__ds__extract_year - , subq_8.listing__ds__extract_quarter - , subq_8.listing__ds__extract_month - , subq_8.listing__ds__extract_day - , subq_8.listing__ds__extract_dow - , subq_8.listing__ds__extract_doy - , subq_8.listing__created_at__day - , subq_8.listing__created_at__week - , subq_8.listing__created_at__month - , subq_8.listing__created_at__quarter - , subq_8.listing__created_at__year - , subq_8.listing__created_at__extract_year - , subq_8.listing__created_at__extract_quarter - , subq_8.listing__created_at__extract_month - , subq_8.listing__created_at__extract_day - , subq_8.listing__created_at__extract_dow - , subq_8.listing__created_at__extract_doy - , subq_8.metric_time__day - , subq_8.listing - , subq_8.user - , subq_8.listing__user - , subq_8.country_latest - , subq_8.is_lux_latest - , subq_8.capacity_latest - , subq_8.listing__country_latest - , subq_8.listing__is_lux_latest - , subq_8.listing__capacity_latest - , subq_8.user__home_state_latest - , subq_8.listings - , subq_8.largest_listing - , subq_8.smallest_listing + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.metric_time__day + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.user__home_state_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing FROM ( -- Join Standard Outputs SELECT - subq_2.ds__day AS ds__day - , subq_2.ds__week AS ds__week - , subq_2.ds__month AS ds__month - , subq_2.ds__quarter AS ds__quarter - , subq_2.ds__year AS ds__year - , subq_2.ds__extract_year AS ds__extract_year - , subq_2.ds__extract_quarter AS ds__extract_quarter - , subq_2.ds__extract_month AS ds__extract_month - , subq_2.ds__extract_day AS ds__extract_day - , subq_2.ds__extract_dow AS ds__extract_dow - , subq_2.ds__extract_doy AS ds__extract_doy - , subq_2.created_at__day AS created_at__day - , subq_2.created_at__week AS created_at__week - , subq_2.created_at__month AS created_at__month - , subq_2.created_at__quarter AS created_at__quarter - , subq_2.created_at__year AS created_at__year - , subq_2.created_at__extract_year AS created_at__extract_year - , subq_2.created_at__extract_quarter AS created_at__extract_quarter - , subq_2.created_at__extract_month AS created_at__extract_month - , subq_2.created_at__extract_day AS created_at__extract_day - , subq_2.created_at__extract_dow AS created_at__extract_dow - , subq_2.created_at__extract_doy AS created_at__extract_doy - , subq_2.listing__ds__day AS listing__ds__day - , subq_2.listing__ds__week AS listing__ds__week - , subq_2.listing__ds__month AS listing__ds__month - , subq_2.listing__ds__quarter AS listing__ds__quarter - , subq_2.listing__ds__year AS listing__ds__year - , subq_2.listing__ds__extract_year AS listing__ds__extract_year - , subq_2.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_2.listing__ds__extract_month AS listing__ds__extract_month - , subq_2.listing__ds__extract_day AS listing__ds__extract_day - , subq_2.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_2.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_2.listing__created_at__day AS listing__created_at__day - , subq_2.listing__created_at__week AS listing__created_at__week - , subq_2.listing__created_at__month AS listing__created_at__month - , subq_2.listing__created_at__quarter AS listing__created_at__quarter - , subq_2.listing__created_at__year AS listing__created_at__year - , subq_2.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_2.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_2.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_2.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_2.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_2.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_5.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_2.user AS user - , subq_2.listing__user AS listing__user - , subq_2.country_latest AS country_latest - , subq_2.is_lux_latest AS is_lux_latest - , subq_2.capacity_latest AS capacity_latest - , subq_2.listing__country_latest AS listing__country_latest - , subq_2.listing__is_lux_latest AS listing__is_lux_latest - , subq_2.listing__capacity_latest AS listing__capacity_latest - , subq_7.home_state_latest AS user__home_state_latest - , subq_2.listings AS listings - , subq_2.largest_listing AS largest_listing - , subq_2.smallest_listing AS smallest_listing + 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.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_3.metric_time__day AS metric_time__day + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_5.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -185,36 +185,36 @@ 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_2 + ) subq_0 CROSS JOIN ( -- Pass Only Elements: ['metric_time__day',] SELECT - subq_4.metric_time__day + subq_2.metric_time__day FROM ( -- Metric Time Dimension 'ds' SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy + subq_1.ds__day + , subq_1.ds__week + , subq_1.ds__month + , subq_1.ds__quarter + , subq_1.ds__year + , subq_1.ds__extract_year + , subq_1.ds__extract_quarter + , subq_1.ds__extract_month + , subq_1.ds__extract_day + , subq_1.ds__extract_dow + , subq_1.ds__extract_doy + , subq_1.ds__day AS metric_time__day + , subq_1.ds__week AS metric_time__week + , subq_1.ds__month AS metric_time__month + , subq_1.ds__quarter AS metric_time__quarter + , subq_1.ds__year AS metric_time__year + , subq_1.ds__extract_year AS metric_time__extract_year + , subq_1.ds__extract_quarter AS metric_time__extract_quarter + , subq_1.ds__extract_month AS metric_time__extract_month + , subq_1.ds__extract_day AS metric_time__extract_day + , subq_1.ds__extract_dow AS metric_time__extract_dow + , subq_1.ds__extract_doy AS metric_time__extract_doy FROM ( -- Time Spine SELECT @@ -230,14 +230,14 @@ FROM ( , EXTRACT(DAY_OF_WEEK FROM time_spine_src_28000.ds) AS ds__extract_dow , EXTRACT(doy FROM time_spine_src_28000.ds) AS ds__extract_doy FROM ***************************.mf_time_spine time_spine_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 + ) subq_1 + ) subq_2 + ) subq_3 FULL OUTER JOIN ( -- Pass Only Elements: ['home_state_latest', 'user'] SELECT - subq_6.user - , subq_6.home_state_latest + subq_4.user + , subq_4.home_state_latest FROM ( -- Read Elements From Semantic Model 'users_latest' SELECT @@ -267,14 +267,14 @@ FROM ( , users_latest_src_28000.home_state_latest AS user__home_state_latest , users_latest_src_28000.user_id AS user FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_6 - ) subq_7 + ) subq_4 + ) subq_5 ON - subq_2.user = subq_7.user - ) subq_8 - WHERE subq_8.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-03' -) subq_9 + subq_0.user = subq_5.user + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-03' +) subq_7 GROUP BY - subq_9.metric_time__day - , subq_9.listing__is_lux_latest - , subq_9.user__home_state_latest + subq_7.metric_time__day + , subq_7.listing__is_lux_latest + , subq_7.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_dimensions_with_time_constraint__plan0.xml b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_dimensions_with_time_constraint__plan0.xml index e7f2570193..e81db14dc9 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_dimensions_with_time_constraint__plan0.xml +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_dimensions_with_time_constraint__plan0.xml @@ -2,438 +2,431 @@ - - + + - + - - + + - + - + - + - - - - - - + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - - - - - - + + + + + + - + - + - - + + - - + + @@ -681,114 +674,114 @@ - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + @@ -856,11 +849,11 @@ - - + + - + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..b5c88a2d39 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_15.metric_time__day + , CAST(subq_15.average_booking_value AS FLOAT64) / CAST(NULLIF(subq_15.max_booking_value, 0) AS FLOAT64) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.average_booking_value) AS average_booking_value + , MAX(subq_14.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__day + , subq_8.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , AVG(subq_7.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + WHERE booking__is_instant + ) subq_6 + ) subq_7 + GROUP BY + metric_time__day + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_13.metric_time__day + , subq_13.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_12.metric_time__day + , MAX(subq_12.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.max_booking_value + 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_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 + 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_10 + ) subq_11 + ) subq_12 + GROUP BY + metric_time__day + ) subq_13 + ) subq_14 + ON + subq_9.metric_time__day = subq_14.metric_time__day + GROUP BY + metric_time__day +) subq_15 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..e890acfa23 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS FLOAT64) / CAST(NULLIF(max_booking_value, 0) AS FLOAT64) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.average_booking_value) AS average_booking_value + , MAX(subq_28.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATETIME_TRUNC(ds, day) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_23 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATETIME_TRUNC(ds, day) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + metric_time__day + ) subq_28 + ON + subq_23.metric_time__day = subq_28.metric_time__day + GROUP BY + metric_time__day +) subq_29 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..c984a7db7b --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,294 @@ +-- Compute Metrics via Expressions +SELECT + subq_12.user__home_state_latest + , subq_12.listings +FROM ( + -- Aggregate Measures + SELECT + subq_11.user__home_state_latest + , SUM(subq_11.listings) AS listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest'] + SELECT + subq_10.user__home_state_latest + , subq_10.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.listing__is_lux_latest + , subq_9.listing__capacity_latest + , subq_9.user__home_state_latest + , subq_9.listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_8.listing__is_lux_latest + , subq_8.listing__capacity_latest + , subq_8.user__home_state_latest + , subq_8.listings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.user AS user + , subq_5.listing__is_lux_latest AS listing__is_lux_latest + , subq_5.listing__capacity_latest AS listing__capacity_latest + , subq_7.home_state_latest AS user__home_state_latest + , subq_5.listings AS listings + FROM ( + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_4.user + , subq_4.listing__is_lux_latest + , subq_4.listing__capacity_latest + , subq_4.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS metric_time__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS ds__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS ds__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS ds__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS ds__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS created_at__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS created_at__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS created_at__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS created_at__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS listing__ds__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__ds__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS listing__ds__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__ds__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS listing__created_at__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__created_at__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS listing__created_at__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__created_at__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_6.user + , subq_6.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATETIME_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day + , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week + , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month + , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter + , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATETIME_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day + , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week + , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month + , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter + , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_6 + ) subq_7 + ON + subq_5.user = subq_7.user + ) subq_8 + ) subq_9 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_10 + ) subq_11 + GROUP BY + user__home_state_latest +) subq_12 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..76b28308ab --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,43 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['listings', 'user__home_state_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + user__home_state_latest + , SUM(listings) AS listings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_16.listing__is_lux_latest AS listing__is_lux_latest + , subq_16.listing__capacity_latest AS listing__capacity_latest + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_16.listings AS listings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_14.user + , listing__is_lux_latest + , listing__capacity_latest + , listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + SELECT + user_id AS user + , is_lux AS listing__is_lux_latest + , capacity AS listing__capacity_latest + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_14 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_16 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + subq_16.user = users_latest_src_28000.user_id +) subq_20 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + user__home_state_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..23583eeea0 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS FLOAT64) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS FLOAT64) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS account__ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS account__ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS account__ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS account__ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS account__ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATETIME_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day + , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week + , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month + , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter + , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATETIME_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day + , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week + , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month + , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter + , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS account__ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS account__ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS account__ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS account__ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS account__ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATETIME_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day + , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week + , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month + , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter + , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATETIME_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day + , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week + , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month + , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter + , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS account__ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS account__ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS account__ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS account__ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS account__ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATETIME_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day + , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week + , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month + , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter + , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATETIME_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day + , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week + , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month + , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter + , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS account__ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS account__ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS account__ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS account__ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS account__ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATETIME_TRUNC(users_latest_src_28000.ds, day) AS ds_latest__day + , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS ds_latest__week + , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS ds_latest__month + , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS ds_latest__quarter + , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATETIME_TRUNC(users_latest_src_28000.ds, day) AS user__ds_latest__day + , DATETIME_TRUNC(users_latest_src_28000.ds, isoweek) AS user__ds_latest__week + , DATETIME_TRUNC(users_latest_src_28000.ds, month) AS user__ds_latest__month + , DATETIME_TRUNC(users_latest_src_28000.ds, quarter) AS user__ds_latest__quarter + , DATETIME_TRUNC(users_latest_src_28000.ds, year) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_28000.ds) - 1) AS user__ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..84e58ea333 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS FLOAT64) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS FLOAT64) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..64ffc315e3 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS FLOAT64) / CAST(NULLIF(subq_19.max_booking_value, 0) AS FLOAT64) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + 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.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__day + , 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 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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 + 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_14 + ) subq_15 + ) subq_16 + GROUP BY + metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + metric_time__day +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..73efe99bfc --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS FLOAT64) / CAST(NULLIF(max_booking_value, 0) AS FLOAT64) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATETIME_TRUNC(ds, day) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATETIME_TRUNC(ds, day) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + metric_time__day + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + metric_time__day +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..8a18d11644 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.listing__country_latest + , subq_13.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_12.listing__country_latest + , SUM(subq_12.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_11.listing__country_latest + , subq_11.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_10.booking__is_instant + , subq_10.listing__country_latest + , subq_10.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_9.booking__is_instant + , subq_9.listing__country_latest + , subq_9.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.listing AS listing + , subq_5.booking__is_instant AS booking__is_instant + , subq_8.country_latest AS listing__country_latest + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_4.listing + , subq_4.booking__is_instant + , subq_4.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_7.listing + , subq_7.country_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS ds__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS ds__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS ds__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS ds__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS created_at__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS created_at__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS created_at__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS created_at__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS listing__ds__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__ds__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS listing__ds__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__ds__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS listing__created_at__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__created_at__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS listing__created_at__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__created_at__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_6 + ) subq_7 + ) subq_8 + ON + subq_5.listing = subq_8.listing + ) subq_9 + ) subq_10 + WHERE booking__is_instant + ) subq_11 + ) subq_12 + GROUP BY + listing__country_latest +) subq_13 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..e1420879c4 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_17.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_17.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE booking__is_instant + ) subq_17 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_17.listing = listings_latest_src_28000.listing_id +) subq_22 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..945c329d57 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + 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 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS ds__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS ds__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS ds__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS ds__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS created_at__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS created_at__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS created_at__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS created_at__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS listing__ds__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__ds__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS listing__ds__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__ds__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATETIME_TRUNC(listings_latest_src_28000.created_at, day) AS listing__created_at__day + , DATETIME_TRUNC(listings_latest_src_28000.created_at, isoweek) AS listing__created_at__week + , DATETIME_TRUNC(listings_latest_src_28000.created_at, month) AS listing__created_at__month + , DATETIME_TRUNC(listings_latest_src_28000.created_at, quarter) AS listing__created_at__quarter + , DATETIME_TRUNC(listings_latest_src_28000.created_at, year) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_28000.created_at) - 1) AS listing__created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/BigQuery/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..5d770f3f36 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_15.metric_time__day + , CAST(subq_15.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_15.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.average_booking_value) AS average_booking_value + , MAX(subq_14.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__day + , subq_8.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , AVG(subq_7.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + WHERE booking__is_instant + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_13.metric_time__day + , subq_13.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_12.metric_time__day + , MAX(subq_12.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.max_booking_value + 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_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 + 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_10 + ) subq_11 + ) subq_12 + GROUP BY + subq_12.metric_time__day + ) subq_13 + ) subq_14 + ON + subq_9.metric_time__day = subq_14.metric_time__day + GROUP BY + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..db345ac389 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.average_booking_value) AS average_booking_value + , MAX(subq_28.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_23 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_28 + ON + subq_23.metric_time__day = subq_28.metric_time__day + GROUP BY + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..35f2ac06a8 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,294 @@ +-- Compute Metrics via Expressions +SELECT + subq_12.user__home_state_latest + , subq_12.listings +FROM ( + -- Aggregate Measures + SELECT + subq_11.user__home_state_latest + , SUM(subq_11.listings) AS listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest'] + SELECT + subq_10.user__home_state_latest + , subq_10.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.listing__is_lux_latest + , subq_9.listing__capacity_latest + , subq_9.user__home_state_latest + , subq_9.listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_8.listing__is_lux_latest + , subq_8.listing__capacity_latest + , subq_8.user__home_state_latest + , subq_8.listings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.user AS user + , subq_5.listing__is_lux_latest AS listing__is_lux_latest + , subq_5.listing__capacity_latest AS listing__capacity_latest + , subq_7.home_state_latest AS user__home_state_latest + , subq_5.listings AS listings + FROM ( + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_4.user + , subq_4.listing__is_lux_latest + , subq_4.listing__capacity_latest + , subq_4.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS metric_time__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_6.user + , subq_6.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_6 + ) subq_7 + ON + subq_5.user = subq_7.user + ) subq_8 + ) subq_9 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_10 + ) subq_11 + GROUP BY + subq_11.user__home_state_latest +) subq_12 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..76b28308ab --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,43 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['listings', 'user__home_state_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + user__home_state_latest + , SUM(listings) AS listings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_16.listing__is_lux_latest AS listing__is_lux_latest + , subq_16.listing__capacity_latest AS listing__capacity_latest + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_16.listings AS listings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_14.user + , listing__is_lux_latest + , listing__capacity_latest + , listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + SELECT + user_id AS user + , is_lux AS listing__is_lux_latest + , capacity AS listing__capacity_latest + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_14 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_16 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + subq_16.user = users_latest_src_28000.user_id +) subq_20 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + user__home_state_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..9022b49e18 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..44eac537d1 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..eba0dec278 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_19.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + 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.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__day + , 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 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + subq_11.metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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 + 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_14 + ) subq_15 + ) subq_16 + GROUP BY + subq_16.metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..111a82caa8 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..41d8a84d8a --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.listing__country_latest + , subq_13.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_12.listing__country_latest + , SUM(subq_12.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_11.listing__country_latest + , subq_11.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_10.booking__is_instant + , subq_10.listing__country_latest + , subq_10.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_9.booking__is_instant + , subq_9.listing__country_latest + , subq_9.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.listing AS listing + , subq_5.booking__is_instant AS booking__is_instant + , subq_8.country_latest AS listing__country_latest + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_4.listing + , subq_4.booking__is_instant + , subq_4.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_7.listing + , subq_7.country_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_6 + ) subq_7 + ) subq_8 + ON + subq_5.listing = subq_8.listing + ) subq_9 + ) subq_10 + WHERE booking__is_instant + ) subq_11 + ) subq_12 + GROUP BY + subq_12.listing__country_latest +) subq_13 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..e1420879c4 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_17.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_17.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE booking__is_instant + ) subq_17 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_17.listing = listings_latest_src_28000.listing_id +) subq_22 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..968378bfc3 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + 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 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + subq_9.listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Databricks/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..8088d8d684 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_15.metric_time__day + , CAST(subq_15.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_15.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.average_booking_value) AS average_booking_value + , MAX(subq_14.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__day + , subq_8.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , AVG(subq_7.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + WHERE booking__is_instant + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_13.metric_time__day + , subq_13.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_12.metric_time__day + , MAX(subq_12.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.max_booking_value + 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_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 + 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_10 + ) subq_11 + ) subq_12 + GROUP BY + subq_12.metric_time__day + ) subq_13 + ) subq_14 + ON + subq_9.metric_time__day = subq_14.metric_time__day + GROUP BY + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..db345ac389 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.average_booking_value) AS average_booking_value + , MAX(subq_28.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_23 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_28 + ON + subq_23.metric_time__day = subq_28.metric_time__day + GROUP BY + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..e20f1a70d6 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,294 @@ +-- Compute Metrics via Expressions +SELECT + subq_12.user__home_state_latest + , subq_12.listings +FROM ( + -- Aggregate Measures + SELECT + subq_11.user__home_state_latest + , SUM(subq_11.listings) AS listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest'] + SELECT + subq_10.user__home_state_latest + , subq_10.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.listing__is_lux_latest + , subq_9.listing__capacity_latest + , subq_9.user__home_state_latest + , subq_9.listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_8.listing__is_lux_latest + , subq_8.listing__capacity_latest + , subq_8.user__home_state_latest + , subq_8.listings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.user AS user + , subq_5.listing__is_lux_latest AS listing__is_lux_latest + , subq_5.listing__capacity_latest AS listing__capacity_latest + , subq_7.home_state_latest AS user__home_state_latest + , subq_5.listings AS listings + FROM ( + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_4.user + , subq_4.listing__is_lux_latest + , subq_4.listing__capacity_latest + , subq_4.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS metric_time__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_6.user + , subq_6.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_6 + ) subq_7 + ON + subq_5.user = subq_7.user + ) subq_8 + ) subq_9 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_10 + ) subq_11 + GROUP BY + subq_11.user__home_state_latest +) subq_12 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..76b28308ab --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,43 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['listings', 'user__home_state_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + user__home_state_latest + , SUM(listings) AS listings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_16.listing__is_lux_latest AS listing__is_lux_latest + , subq_16.listing__capacity_latest AS listing__capacity_latest + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_16.listings AS listings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_14.user + , listing__is_lux_latest + , listing__capacity_latest + , listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + SELECT + user_id AS user + , is_lux AS listing__is_lux_latest + , capacity AS listing__capacity_latest + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_14 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_16 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + subq_16.user = users_latest_src_28000.user_id +) subq_20 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + user__home_state_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..a4d7c09a3c --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..44eac537d1 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..8088d8d684 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_15.metric_time__day + , CAST(subq_15.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_15.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.average_booking_value) AS average_booking_value + , MAX(subq_14.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__day + , subq_8.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , AVG(subq_7.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + WHERE booking__is_instant + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_13.metric_time__day + , subq_13.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_12.metric_time__day + , MAX(subq_12.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.max_booking_value + 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_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 + 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_10 + ) subq_11 + ) subq_12 + GROUP BY + subq_12.metric_time__day + ) subq_13 + ) subq_14 + ON + subq_9.metric_time__day = subq_14.metric_time__day + GROUP BY + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..db345ac389 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.average_booking_value) AS average_booking_value + , MAX(subq_28.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_23 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_28 + ON + subq_23.metric_time__day = subq_28.metric_time__day + GROUP BY + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_distinct_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_distinct_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..a4d7c09a3c --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_distinct_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_distinct_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_distinct_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..44eac537d1 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_distinct_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..388b3ec95a --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.listing__country_latest + , subq_13.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_12.listing__country_latest + , SUM(subq_12.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_11.listing__country_latest + , subq_11.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_10.booking__is_instant + , subq_10.listing__country_latest + , subq_10.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_9.booking__is_instant + , subq_9.listing__country_latest + , subq_9.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.listing AS listing + , subq_5.booking__is_instant AS booking__is_instant + , subq_8.country_latest AS listing__country_latest + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_4.listing + , subq_4.booking__is_instant + , subq_4.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_7.listing + , subq_7.country_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_6 + ) subq_7 + ) subq_8 + ON + subq_5.listing = subq_8.listing + ) subq_9 + ) subq_10 + WHERE booking__is_instant + ) subq_11 + ) subq_12 + GROUP BY + subq_12.listing__country_latest +) subq_13 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..e1420879c4 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_17.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_17.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE booking__is_instant + ) subq_17 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_17.listing = listings_latest_src_28000.listing_id +) subq_22 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..a62b838b8c --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + 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 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + subq_9.listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..9912778c27 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_15.metric_time__day + , CAST(subq_15.average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(subq_15.max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.average_booking_value) AS average_booking_value + , MAX(subq_14.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__day + , subq_8.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , AVG(subq_7.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + WHERE booking__is_instant + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_13.metric_time__day + , subq_13.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_12.metric_time__day + , MAX(subq_12.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.max_booking_value + 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_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 + 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_10 + ) subq_11 + ) subq_12 + GROUP BY + subq_12.metric_time__day + ) subq_13 + ) subq_14 + ON + subq_9.metric_time__day = subq_14.metric_time__day + GROUP BY + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..0c1698db23 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.average_booking_value) AS average_booking_value + , MAX(subq_28.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_23 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_28 + ON + subq_23.metric_time__day = subq_28.metric_time__day + GROUP BY + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..e20f1a70d6 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,294 @@ +-- Compute Metrics via Expressions +SELECT + subq_12.user__home_state_latest + , subq_12.listings +FROM ( + -- Aggregate Measures + SELECT + subq_11.user__home_state_latest + , SUM(subq_11.listings) AS listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest'] + SELECT + subq_10.user__home_state_latest + , subq_10.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.listing__is_lux_latest + , subq_9.listing__capacity_latest + , subq_9.user__home_state_latest + , subq_9.listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_8.listing__is_lux_latest + , subq_8.listing__capacity_latest + , subq_8.user__home_state_latest + , subq_8.listings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.user AS user + , subq_5.listing__is_lux_latest AS listing__is_lux_latest + , subq_5.listing__capacity_latest AS listing__capacity_latest + , subq_7.home_state_latest AS user__home_state_latest + , subq_5.listings AS listings + FROM ( + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_4.user + , subq_4.listing__is_lux_latest + , subq_4.listing__capacity_latest + , subq_4.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS metric_time__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_6.user + , subq_6.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_6 + ) subq_7 + ON + subq_5.user = subq_7.user + ) subq_8 + ) subq_9 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_10 + ) subq_11 + GROUP BY + subq_11.user__home_state_latest +) subq_12 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..76b28308ab --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,43 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['listings', 'user__home_state_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + user__home_state_latest + , SUM(listings) AS listings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_16.listing__is_lux_latest AS listing__is_lux_latest + , subq_16.listing__capacity_latest AS listing__capacity_latest + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_16.listings AS listings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_14.user + , listing__is_lux_latest + , listing__capacity_latest + , listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + SELECT + user_id AS user + , is_lux AS listing__is_lux_latest + , capacity AS listing__capacity_latest + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_14 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_16 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + subq_16.user = users_latest_src_28000.user_id +) subq_20 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + user__home_state_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..e1b07ee2ad --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE PRECISION) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE PRECISION) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..80c554f04a --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE PRECISION) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE PRECISION) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..f11c286f44 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(subq_19.max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + 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.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__day + , 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 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + subq_11.metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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 + 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_14 + ) subq_15 + ) subq_16 + GROUP BY + subq_16.metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..8fd9bd5080 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..388b3ec95a --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.listing__country_latest + , subq_13.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_12.listing__country_latest + , SUM(subq_12.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_11.listing__country_latest + , subq_11.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_10.booking__is_instant + , subq_10.listing__country_latest + , subq_10.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_9.booking__is_instant + , subq_9.listing__country_latest + , subq_9.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.listing AS listing + , subq_5.booking__is_instant AS booking__is_instant + , subq_8.country_latest AS listing__country_latest + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_4.listing + , subq_4.booking__is_instant + , subq_4.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_7.listing + , subq_7.country_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_6 + ) subq_7 + ) subq_8 + ON + subq_5.listing = subq_8.listing + ) subq_9 + ) subq_10 + WHERE booking__is_instant + ) subq_11 + ) subq_12 + GROUP BY + subq_12.listing__country_latest +) subq_13 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..e1420879c4 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_17.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_17.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE booking__is_instant + ) subq_17 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_17.listing = listings_latest_src_28000.listing_id +) subq_22 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..a62b838b8c --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + 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 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + subq_9.listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Postgres/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..6a9a9bf836 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_15.metric_time__day + , CAST(subq_15.average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(subq_15.max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.average_booking_value) AS average_booking_value + , MAX(subq_14.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__day + , subq_8.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , AVG(subq_7.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + WHERE booking__is_instant + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_13.metric_time__day + , subq_13.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_12.metric_time__day + , MAX(subq_12.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.max_booking_value + 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_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 + 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_10 + ) subq_11 + ) subq_12 + GROUP BY + subq_12.metric_time__day + ) subq_13 + ) subq_14 + ON + subq_9.metric_time__day = subq_14.metric_time__day + GROUP BY + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..0c1698db23 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.average_booking_value) AS average_booking_value + , MAX(subq_28.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_23 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_28 + ON + subq_23.metric_time__day = subq_28.metric_time__day + GROUP BY + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..e889913967 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,294 @@ +-- Compute Metrics via Expressions +SELECT + subq_12.user__home_state_latest + , subq_12.listings +FROM ( + -- Aggregate Measures + SELECT + subq_11.user__home_state_latest + , SUM(subq_11.listings) AS listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest'] + SELECT + subq_10.user__home_state_latest + , subq_10.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.listing__is_lux_latest + , subq_9.listing__capacity_latest + , subq_9.user__home_state_latest + , subq_9.listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_8.listing__is_lux_latest + , subq_8.listing__capacity_latest + , subq_8.user__home_state_latest + , subq_8.listings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.user AS user + , subq_5.listing__is_lux_latest AS listing__is_lux_latest + , subq_5.listing__capacity_latest AS listing__capacity_latest + , subq_7.home_state_latest AS user__home_state_latest + , subq_5.listings AS listings + FROM ( + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_4.user + , subq_4.listing__is_lux_latest + , subq_4.listing__capacity_latest + , subq_4.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS metric_time__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_6.user + , subq_6.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_6 + ) subq_7 + ON + subq_5.user = subq_7.user + ) subq_8 + ) subq_9 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_10 + ) subq_11 + GROUP BY + subq_11.user__home_state_latest +) subq_12 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..76b28308ab --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,43 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['listings', 'user__home_state_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + user__home_state_latest + , SUM(listings) AS listings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_16.listing__is_lux_latest AS listing__is_lux_latest + , subq_16.listing__capacity_latest AS listing__capacity_latest + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_16.listings AS listings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_14.user + , listing__is_lux_latest + , listing__capacity_latest + , listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + SELECT + user_id AS user + , is_lux AS listing__is_lux_latest + , capacity AS listing__capacity_latest + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_14 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_16 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + subq_16.user = users_latest_src_28000.user_id +) subq_20 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + user__home_state_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..d04c175116 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE PRECISION) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE PRECISION) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_28000.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_28000.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_28000.ds) END AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..80c554f04a --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE PRECISION) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE PRECISION) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..447784aa01 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(subq_19.max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + 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.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__day + , 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 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + subq_11.metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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 + 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_14 + ) subq_15 + ) subq_16 + GROUP BY + subq_16.metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..8fd9bd5080 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE PRECISION) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..107ed57509 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.listing__country_latest + , subq_13.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_12.listing__country_latest + , SUM(subq_12.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_11.listing__country_latest + , subq_11.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_10.booking__is_instant + , subq_10.listing__country_latest + , subq_10.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_9.booking__is_instant + , subq_9.listing__country_latest + , subq_9.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.listing AS listing + , subq_5.booking__is_instant AS booking__is_instant + , subq_8.country_latest AS listing__country_latest + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_4.listing + , subq_4.booking__is_instant + , subq_4.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_7.listing + , subq_7.country_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_6 + ) subq_7 + ) subq_8 + ON + subq_5.listing = subq_8.listing + ) subq_9 + ) subq_10 + WHERE booking__is_instant + ) subq_11 + ) subq_12 + GROUP BY + subq_12.listing__country_latest +) subq_13 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..e1420879c4 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_17.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_17.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE booking__is_instant + ) subq_17 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_17.listing = listings_latest_src_28000.listing_id +) subq_22 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..2c072d5394 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + 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 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_28000.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_28000.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_28000.created_at) END AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + subq_9.listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Redshift/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..b99de580a3 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_15.metric_time__day + , CAST(subq_15.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_15.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.average_booking_value) AS average_booking_value + , MAX(subq_14.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__day + , subq_8.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , AVG(subq_7.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + WHERE booking__is_instant + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_13.metric_time__day + , subq_13.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_12.metric_time__day + , MAX(subq_12.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.max_booking_value + 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_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 + 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_10 + ) subq_11 + ) subq_12 + GROUP BY + subq_12.metric_time__day + ) subq_13 + ) subq_14 + ON + subq_9.metric_time__day = subq_14.metric_time__day + GROUP BY + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..db345ac389 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.average_booking_value) AS average_booking_value + , MAX(subq_28.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_23 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_28 + ON + subq_23.metric_time__day = subq_28.metric_time__day + GROUP BY + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..e1c91ce539 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,294 @@ +-- Compute Metrics via Expressions +SELECT + subq_12.user__home_state_latest + , subq_12.listings +FROM ( + -- Aggregate Measures + SELECT + subq_11.user__home_state_latest + , SUM(subq_11.listings) AS listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest'] + SELECT + subq_10.user__home_state_latest + , subq_10.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.listing__is_lux_latest + , subq_9.listing__capacity_latest + , subq_9.user__home_state_latest + , subq_9.listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_8.listing__is_lux_latest + , subq_8.listing__capacity_latest + , subq_8.user__home_state_latest + , subq_8.listings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.user AS user + , subq_5.listing__is_lux_latest AS listing__is_lux_latest + , subq_5.listing__capacity_latest AS listing__capacity_latest + , subq_7.home_state_latest AS user__home_state_latest + , subq_5.listings AS listings + FROM ( + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_4.user + , subq_4.listing__is_lux_latest + , subq_4.listing__capacity_latest + , subq_4.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS metric_time__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_6.user + , subq_6.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_6 + ) subq_7 + ON + subq_5.user = subq_7.user + ) subq_8 + ) subq_9 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_10 + ) subq_11 + GROUP BY + subq_11.user__home_state_latest +) subq_12 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..76b28308ab --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,43 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['listings', 'user__home_state_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + user__home_state_latest + , SUM(listings) AS listings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_16.listing__is_lux_latest AS listing__is_lux_latest + , subq_16.listing__capacity_latest AS listing__capacity_latest + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_16.listings AS listings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_14.user + , listing__is_lux_latest + , listing__capacity_latest + , listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + SELECT + user_id AS user + , is_lux AS listing__is_lux_latest + , capacity AS listing__capacity_latest + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_14 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_16 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + subq_16.user = users_latest_src_28000.user_id +) subq_20 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + user__home_state_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..f3103e613f --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..44eac537d1 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..fac10af629 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_19.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + 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.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__day + , 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 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + subq_11.metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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 + 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_14 + ) subq_15 + ) subq_16 + GROUP BY + subq_16.metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..111a82caa8 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..0c3cde2ebe --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.listing__country_latest + , subq_13.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_12.listing__country_latest + , SUM(subq_12.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_11.listing__country_latest + , subq_11.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_10.booking__is_instant + , subq_10.listing__country_latest + , subq_10.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_9.booking__is_instant + , subq_9.listing__country_latest + , subq_9.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.listing AS listing + , subq_5.booking__is_instant AS booking__is_instant + , subq_8.country_latest AS listing__country_latest + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_4.listing + , subq_4.booking__is_instant + , subq_4.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_7.listing + , subq_7.country_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_6 + ) subq_7 + ) subq_8 + ON + subq_5.listing = subq_8.listing + ) subq_9 + ) subq_10 + WHERE booking__is_instant + ) subq_11 + ) subq_12 + GROUP BY + subq_12.listing__country_latest +) subq_13 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..e1420879c4 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_17.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_17.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE booking__is_instant + ) subq_17 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_17.listing = listings_latest_src_28000.listing_id +) subq_22 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..00cabc8f0d --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + 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 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + subq_9.listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Snowflake/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..c939f6d0df --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_15.metric_time__day + , CAST(subq_15.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_15.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.average_booking_value) AS average_booking_value + , MAX(subq_14.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__day + , subq_8.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__day + , AVG(subq_7.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_6.metric_time__day + , subq_6.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + WHERE booking__is_instant + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__day + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_13.metric_time__day + , subq_13.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_12.metric_time__day + , MAX(subq_12.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.max_booking_value + 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_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 + 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_10 + ) subq_11 + ) subq_12 + GROUP BY + subq_12.metric_time__day + ) subq_13 + ) subq_14 + ON + subq_9.metric_time__day = subq_14.metric_time__day + GROUP BY + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..db345ac389 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.average_booking_value) AS average_booking_value + , MAX(subq_28.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_23 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_28 + ON + subq_23.metric_time__day = subq_28.metric_time__day + GROUP BY + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..15d9663ea3 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,294 @@ +-- Compute Metrics via Expressions +SELECT + subq_12.user__home_state_latest + , subq_12.listings +FROM ( + -- Aggregate Measures + SELECT + subq_11.user__home_state_latest + , SUM(subq_11.listings) AS listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest'] + SELECT + subq_10.user__home_state_latest + , subq_10.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.listing__is_lux_latest + , subq_9.listing__capacity_latest + , subq_9.user__home_state_latest + , subq_9.listings + FROM ( + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_8.listing__is_lux_latest + , subq_8.listing__capacity_latest + , subq_8.user__home_state_latest + , subq_8.listings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.user AS user + , subq_5.listing__is_lux_latest AS listing__is_lux_latest + , subq_5.listing__capacity_latest AS listing__capacity_latest + , subq_7.home_state_latest AS user__home_state_latest + , subq_5.listings AS listings + FROM ( + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_4.user + , subq_4.listing__is_lux_latest + , subq_4.listing__capacity_latest + , subq_4.listings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS metric_time__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_6.user + , subq_6.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_6 + ) subq_7 + ON + subq_5.user = subq_7.user + ) subq_8 + ) subq_9 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_10 + ) subq_11 + GROUP BY + subq_11.user__home_state_latest +) subq_12 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..76b28308ab --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,43 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['listings', 'user__home_state_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + user__home_state_latest + , SUM(listings) AS listings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + SELECT + subq_16.listing__is_lux_latest AS listing__is_lux_latest + , subq_16.listing__capacity_latest AS listing__capacity_latest + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , subq_16.listings AS listings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] + SELECT + subq_14.user + , listing__is_lux_latest + , listing__capacity_latest + , listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + SELECT + user_id AS user + , is_lux AS listing__is_lux_latest + , capacity AS listing__capacity_latest + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_14 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_16 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + subq_16.user = users_latest_src_28000.user_id +) subq_20 +WHERE listing__is_lux_latest OR listing__capacity_latest > 4 +GROUP BY + user__home_state_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..0dee0eb985 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0.sql @@ -0,0 +1,651 @@ +-- Compute Metrics via Expressions +SELECT + CAST(subq_28.west_coast_balance_first_day AS DOUBLE) / CAST(NULLIF(subq_28.east_coast_balance_first_dat, 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Combine Aggregated Outputs + SELECT + MAX(subq_13.west_coast_balance_first_day) AS west_coast_balance_first_day + , MAX(subq_27.east_coast_balance_first_dat) AS east_coast_balance_first_dat + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.total_account_balance_first_day AS west_coast_balance_first_day + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_11.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_10.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_7.ds__day AS ds__day + , subq_7.user__home_state_latest AS user__home_state_latest + , subq_7.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_7 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_8.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_6.ds__day + , subq_6.user__home_state_latest + , subq_6.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_5.ds__day + , subq_5.user__home_state_latest + , subq_5.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_2.ds__day AS ds__day + , subq_2.user AS user + , subq_4.home_state_latest AS user__home_state_latest + , subq_2.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_1.ds__day + , subq_1.user + , subq_1.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__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.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.account_balance + , subq_0.total_account_balance_first_day + , subq_0.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_3.user + , subq_3.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ) subq_4 + ON + subq_2.user = subq_4.user + ) subq_5 + ) subq_6 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_8 + ) subq_9 + ON + subq_7.ds__day = subq_9.ds__day__complete + ) subq_10 + ) subq_11 + ) subq_12 + ) subq_13 + CROSS JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_26.total_account_balance_first_day AS east_coast_balance_first_dat + FROM ( + -- Aggregate Measures + SELECT + SUM(subq_25.total_account_balance_first_day) AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day',] + SELECT + subq_24.total_account_balance_first_day + FROM ( + -- Join on MIN(ds) and [] grouping by None + SELECT + subq_21.ds__day AS ds__day + , subq_21.user__home_state_latest AS user__home_state_latest + , subq_21.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_21 + INNER JOIN ( + -- Filter row on MIN(ds__day) + SELECT + MIN(subq_22.ds__day) AS ds__day__complete + FROM ( + -- Constrain Output with WHERE + SELECT + subq_20.ds__day + , subq_20.user__home_state_latest + , subq_20.total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + subq_19.ds__day + , subq_19.user__home_state_latest + , subq_19.total_account_balance_first_day + FROM ( + -- Join Standard Outputs + SELECT + subq_16.ds__day AS ds__day + , subq_16.user AS user + , subq_18.home_state_latest AS user__home_state_latest + , subq_16.total_account_balance_first_day AS total_account_balance_first_day + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day', 'ds__day', 'user'] + SELECT + subq_15.ds__day + , subq_15.user + , subq_15.total_account_balance_first_day + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.account__ds__day + , subq_14.account__ds__week + , subq_14.account__ds__month + , subq_14.account__ds__quarter + , subq_14.account__ds__year + , subq_14.account__ds__extract_year + , subq_14.account__ds__extract_quarter + , subq_14.account__ds__extract_month + , subq_14.account__ds__extract_day + , subq_14.account__ds__extract_dow + , subq_14.account__ds__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.user + , subq_14.account__user + , subq_14.account_type + , subq_14.account__account_type + , subq_14.account_balance + , subq_14.total_account_balance_first_day + , subq_14.current_account_balance_by_user + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_14 + ) subq_15 + ) subq_16 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + subq_17.user + , subq_17.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy + , users_latest_src_28000.home_state_latest + , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day + , EXTRACT(DAY_OF_WEEK FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_17 + ) subq_18 + ON + subq_16.user = subq_18.user + ) subq_19 + ) subq_20 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_22 + ) subq_23 + ON + subq_21.ds__day = subq_23.ds__day__complete + ) subq_24 + ) subq_25 + ) subq_26 + ) subq_27 +) subq_28 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..44eac537d1 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_joined_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,102 @@ +-- Combine Aggregated Outputs +-- Compute Metrics via Expressions +SELECT + CAST(MAX(subq_42.west_coast_balance_first_day) AS DOUBLE) / CAST(NULLIF(MAX(subq_56.east_coast_balance_first_dat), 0) AS DOUBLE) AS regional_starting_balance_ratios +FROM ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_36.total_account_balance_first_day) AS west_coast_balance_first_day + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_36 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_35 + WHERE user__home_state_latest IN ('CA', 'HI', 'WA') + ) subq_38 + ON + subq_36.ds__day = subq_38.ds__day__complete +) subq_42 +CROSS JOIN ( + -- Join on MIN(ds) and [] grouping by None + -- Pass Only Elements: ['total_account_balance_first_day',] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + SUM(subq_50.total_account_balance_first_day) AS east_coast_balance_first_dat + FROM ( + -- Constrain Output with WHERE + SELECT + ds__day + , total_account_balance_first_day + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_50 + INNER JOIN ( + -- Constrain Output with WHERE + -- Filter row on MIN(ds__day) + SELECT + MIN(ds__day) AS ds__day__complete + FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['total_account_balance_first_day', 'user__home_state_latest', 'ds__day'] + SELECT + DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , users_latest_src_28000.home_state_latest AS user__home_state_latest + FROM ***************************.fct_accounts accounts_source_src_28000 + LEFT OUTER JOIN + ***************************.dim_users_latest users_latest_src_28000 + ON + accounts_source_src_28000.user_id = users_latest_src_28000.user_id + ) subq_49 + WHERE user__home_state_latest IN ('MD', 'NY', 'TX') + ) subq_52 + ON + subq_50.ds__day = subq_52.ds__day__complete +) subq_56 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql new file mode 100644 index 0000000000..ce5e6dddef --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -0,0 +1,563 @@ +-- Compute Metrics via Expressions +SELECT + subq_19.metric_time__day + , CAST(subq_19.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_19.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_13.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_12.metric_time__day + , subq_12.average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_11.metric_time__day + , AVG(subq_11.average_booking_value) AS average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + SELECT + subq_10.metric_time__day + , subq_10.average_booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.booking__is_instant + , subq_9.average_booking_value + FROM ( + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + subq_8.metric_time__day + , subq_8.booking__is_instant + , subq_8.average_booking_value + FROM ( + -- Constrain Output with WHERE + 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.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__day + , 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 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , 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 ( + -- 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_6 + ) subq_7 + WHERE booking__is_instant + ) subq_8 + ) subq_9 + WHERE booking__is_instant + ) subq_10 + ) subq_11 + GROUP BY + subq_11.metric_time__day + ) subq_12 + ) subq_13 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_17.metric_time__day + , subq_17.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_16.metric_time__day + , MAX(subq_16.max_booking_value) AS max_booking_value + FROM ( + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_15.metric_time__day + , subq_15.max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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 + 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_14 + ) subq_15 + ) subq_16 + GROUP BY + subq_16.metric_time__day + ) subq_17 + ) subq_18 + ON + subq_13.metric_time__day = subq_18.metric_time__day + GROUP BY + COALESCE(subq_13.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql new file mode 100644 index 0000000000..111a82caa8 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_multiple_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -0,0 +1,58 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , CAST(average_booking_value AS DOUBLE) / CAST(NULLIF(max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_27.average_booking_value) AS average_booking_value + , MAX(subq_32.max_booking_value) AS max_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , AVG(average_booking_value) AS average_booking_value + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] + SELECT + metric_time__day + , booking__is_instant + , average_booking_value + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_21 + WHERE booking__is_instant + ) subq_23 + WHERE booking__is_instant + GROUP BY + metric_time__day + ) subq_27 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , MAX(booking_value) AS max_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + ) subq_32 + ON + subq_27.metric_time__day = subq_32.metric_time__day + GROUP BY + COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0.sql new file mode 100644 index 0000000000..f257d9cbc3 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0.sql @@ -0,0 +1,486 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.listing__country_latest + , subq_13.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_12.listing__country_latest + , SUM(subq_12.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_11.listing__country_latest + , subq_11.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_10.booking__is_instant + , subq_10.listing__country_latest + , subq_10.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_9.booking__is_instant + , subq_9.listing__country_latest + , subq_9.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_5.listing AS listing + , subq_5.booking__is_instant AS booking__is_instant + , subq_8.country_latest AS listing__country_latest + , subq_5.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_4.listing + , subq_4.booking__is_instant + , subq_4.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_7.listing + , subq_7.country_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + 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.created_at__day + , subq_6.created_at__week + , subq_6.created_at__month + , subq_6.created_at__quarter + , subq_6.created_at__year + , subq_6.created_at__extract_year + , subq_6.created_at__extract_quarter + , subq_6.created_at__extract_month + , subq_6.created_at__extract_day + , subq_6.created_at__extract_dow + , subq_6.created_at__extract_doy + , subq_6.listing__ds__day + , subq_6.listing__ds__week + , subq_6.listing__ds__month + , subq_6.listing__ds__quarter + , subq_6.listing__ds__year + , subq_6.listing__ds__extract_year + , subq_6.listing__ds__extract_quarter + , subq_6.listing__ds__extract_month + , subq_6.listing__ds__extract_day + , subq_6.listing__ds__extract_dow + , subq_6.listing__ds__extract_doy + , subq_6.listing__created_at__day + , subq_6.listing__created_at__week + , subq_6.listing__created_at__month + , subq_6.listing__created_at__quarter + , subq_6.listing__created_at__year + , subq_6.listing__created_at__extract_year + , subq_6.listing__created_at__extract_quarter + , subq_6.listing__created_at__extract_month + , subq_6.listing__created_at__extract_day + , subq_6.listing__created_at__extract_dow + , subq_6.listing__created_at__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.listing + , subq_6.user + , subq_6.listing__user + , subq_6.country_latest + , subq_6.is_lux_latest + , subq_6.capacity_latest + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.listing__capacity_latest + , subq_6.listings + , subq_6.largest_listing + , subq_6.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_6 + ) subq_7 + ) subq_8 + ON + subq_5.listing = subq_8.listing + ) subq_9 + ) subq_10 + WHERE booking__is_instant + ) subq_11 + ) subq_12 + GROUP BY + subq_12.listing__country_latest +) subq_13 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..e1420879c4 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -0,0 +1,40 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + SELECT + subq_17.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , subq_17.bookings AS bookings + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_15 + WHERE booking__is_instant + ) subq_17 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_17.listing = listings_latest_src_28000.listing_id +) subq_22 +WHERE booking__is_instant +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0.sql new file mode 100644 index 0000000000..02b7d9119b --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0.sql @@ -0,0 +1,387 @@ +-- Compute Metrics via Expressions +SELECT + subq_10.listing__country_latest + , subq_10.bookings +FROM ( + -- Aggregate Measures + SELECT + subq_9.listing__country_latest + , SUM(subq_9.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest'] + SELECT + subq_8.listing__country_latest + , subq_8.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_7.booking__is_instant + , subq_7.listing__country_latest + , subq_7.listing__is_lux_latest + , subq_7.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_6.booking__is_instant + , subq_6.listing__country_latest + , subq_6.listing__is_lux_latest + , subq_6.bookings + FROM ( + -- Join Standard Outputs + SELECT + subq_2.listing AS listing + , subq_2.booking__is_instant AS booking__is_instant + , subq_5.country_latest AS listing__country_latest + , subq_5.is_lux_latest AS listing__is_lux_latest + , subq_2.bookings AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_1.listing + , subq_1.booking__is_instant + , subq_1.bookings + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 + 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 + ) subq_1 + ) subq_2 + LEFT OUTER JOIN ( + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_4.listing + , subq_4.country_latest + , subq_4.is_lux_latest + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.ds__day AS metric_time__day + , subq_3.ds__week AS metric_time__week + , subq_3.ds__month AS metric_time__month + , subq_3.ds__quarter AS metric_time__quarter + , subq_3.ds__year AS metric_time__year + , subq_3.ds__extract_year AS metric_time__extract_year + , subq_3.ds__extract_quarter AS metric_time__extract_quarter + , subq_3.ds__extract_month AS metric_time__extract_month + , subq_3.ds__extract_day AS metric_time__extract_day + , subq_3.ds__extract_dow AS metric_time__extract_dow + , subq_3.ds__extract_doy AS metric_time__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_3 + ) subq_4 + ) subq_5 + ON + subq_2.listing = subq_5.listing + ) subq_6 + ) subq_7 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_8 + ) subq_9 + GROUP BY + subq_9.listing__country_latest +) subq_10 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0_optimized.sql new file mode 100644 index 0000000000..be31b01767 --- /dev/null +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/Trino/test_skipped_pushdown__plan0_optimized.sql @@ -0,0 +1,33 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: ['bookings', 'listing__country_latest'] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + listing__country_latest + , SUM(bookings) AS bookings +FROM ( + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + SELECT + subq_13.booking__is_instant AS booking__is_instant + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , subq_13.bookings AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + listing_id AS listing + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + LEFT OUTER JOIN + ***************************.dim_listings_latest listings_latest_src_28000 + ON + subq_13.listing = listings_latest_src_28000.listing_id +) subq_18 +WHERE booking__is_instant OR listing__is_lux_latest +GROUP BY + listing__country_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql index 813a04508b..2fb9e4a352 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS FLOAT64) / CAST(NULLIF(subq_12.booking_value, 0) AS FLOAT64) AS instant_booking_value_ratio + subq_15.metric_time__day + , CAST(subq_15.booking_value_with_is_instant_constraint AS FLOAT64) / CAST(NULLIF(subq_15.booking_value, 0) AS FLOAT64) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_14.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_8.metric_time__day + , subq_8.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_7.metric_time__day + , SUM(subq_7.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_6.metric_time__day + , subq_6.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY metric_time__day - ) subq_5 - ) subq_6 + ) subq_8 + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_13.metric_time__day + , subq_13.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.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_8.metric_time__day - , subq_8.booking_value + subq_11.metric_time__day + , subq_11.booking_value 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.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.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.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_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 @@ -446,15 +549,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_7 - ) subq_8 - ) subq_9 + ) subq_10 + ) subq_11 + ) subq_12 GROUP BY metric_time__day - ) subq_10 - ) subq_11 + ) subq_13 + ) subq_14 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_9.metric_time__day = subq_14.metric_time__day GROUP BY metric_time__day -) subq_12 +) subq_15 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql index efac34f0c1..3969c34776 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_28.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATETIME_TRUNC(ds, day) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATETIME_TRUNC(ds, day) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY metric_time__day - ) subq_24 + ) subq_28 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_23.metric_time__day = subq_28.metric_time__day GROUP BY metric_time__day -) subq_25 +) subq_29 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0.sql index 39ccdf1d7f..889072cddd 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_9.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_8.metric_time__day + , subq_8.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE NOT booking__is_instant + ) subq_4 + ) subq_5 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY metric_time__day - ) subq_5 -) subq_6 + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 13fca71a38..b995d87ede 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATETIME_TRUNC(ds, day) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATETIME_TRUNC(ds, day) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + WHERE NOT booking__is_instant + ) subq_13 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_17 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql index 4f2cd9819b..98239358a2 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio + subq_15.metric_time__day + , CAST(subq_15.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_15.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_14.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_8.metric_time__day + , subq_8.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_7.metric_time__day + , SUM(subq_7.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_6.metric_time__day + , subq_6.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 + subq_7.metric_time__day + ) subq_8 + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_13.metric_time__day + , subq_13.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.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_8.metric_time__day - , subq_8.booking_value + subq_11.metric_time__day + , subq_11.booking_value 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.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.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.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_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 @@ -446,15 +549,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_7 - ) subq_8 - ) subq_9 + ) subq_10 + ) subq_11 + ) subq_12 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_12.metric_time__day + ) subq_13 + ) subq_14 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_9.metric_time__day = subq_14.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql index a465dac6f6..b3f811ac19 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_28.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_28 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_23.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0.sql index 87a8c39f99..54cd5f4827 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_9.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_8.metric_time__day + , subq_8.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE NOT booking__is_instant + ) subq_4 + ) subq_5 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_7.metric_time__day + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..31360941eb 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + WHERE NOT booking__is_instant + ) subq_13 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_17 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql index b2323d92df..7a77ad0c8d 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio + subq_15.metric_time__day + , CAST(subq_15.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_15.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_14.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_8.metric_time__day + , subq_8.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_7.metric_time__day + , SUM(subq_7.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_6.metric_time__day + , subq_6.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 + subq_7.metric_time__day + ) subq_8 + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_13.metric_time__day + , subq_13.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.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_8.metric_time__day - , subq_8.booking_value + subq_11.metric_time__day + , subq_11.booking_value 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.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.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.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_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 @@ -446,15 +549,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_7 - ) subq_8 - ) subq_9 + ) subq_10 + ) subq_11 + ) subq_12 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_12.metric_time__day + ) subq_13 + ) subq_14 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_9.metric_time__day = subq_14.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql index a465dac6f6..b3f811ac19 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_28.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_28 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_23.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0.sql index 9182b35971..917ad2f2e1 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_9.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_8.metric_time__day + , subq_8.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE NOT booking__is_instant + ) subq_4 + ) subq_5 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_7.metric_time__day + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..31360941eb 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + WHERE NOT booking__is_instant + ) subq_13 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_17 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql index 19a913bb1f..fdbdd6f898 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE PRECISION) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio + subq_15.metric_time__day + , CAST(subq_15.booking_value_with_is_instant_constraint AS DOUBLE PRECISION) / CAST(NULLIF(subq_15.booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_14.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_8.metric_time__day + , subq_8.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_7.metric_time__day + , SUM(subq_7.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_6.metric_time__day + , subq_6.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 + subq_7.metric_time__day + ) subq_8 + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_13.metric_time__day + , subq_13.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.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_8.metric_time__day - , subq_8.booking_value + subq_11.metric_time__day + , subq_11.booking_value 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.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.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.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_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 @@ -446,15 +549,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_7 - ) subq_8 - ) subq_9 + ) subq_10 + ) subq_11 + ) subq_12 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_12.metric_time__day + ) subq_13 + ) subq_14 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_9.metric_time__day = subq_14.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql index e3a93f4824..9b1533b73c 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_28.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_28 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_23.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0.sql index 9182b35971..917ad2f2e1 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_9.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_8.metric_time__day + , subq_8.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE NOT booking__is_instant + ) subq_4 + ) subq_5 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_7.metric_time__day + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..31360941eb 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + WHERE NOT booking__is_instant + ) subq_13 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_17 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql index cda95b14fc..32673ef241 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE PRECISION) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio + subq_15.metric_time__day + , CAST(subq_15.booking_value_with_is_instant_constraint AS DOUBLE PRECISION) / CAST(NULLIF(subq_15.booking_value, 0) AS DOUBLE PRECISION) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_14.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_8.metric_time__day + , subq_8.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_7.metric_time__day + , SUM(subq_7.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_6.metric_time__day + , subq_6.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 + subq_7.metric_time__day + ) subq_8 + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_13.metric_time__day + , subq_13.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.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_8.metric_time__day - , subq_8.booking_value + subq_11.metric_time__day + , subq_11.booking_value 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.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.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.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_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 @@ -446,15 +549,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_7 - ) subq_8 - ) subq_9 + ) subq_10 + ) subq_11 + ) subq_12 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_12.metric_time__day + ) subq_13 + ) subq_14 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_9.metric_time__day = subq_14.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql index e3a93f4824..9b1533b73c 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_28.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_28 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_23.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0.sql index 6b26ce724b..e6da332c04 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_9.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_8.metric_time__day + , subq_8.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE NOT booking__is_instant + ) subq_4 + ) subq_5 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_7.metric_time__day + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..31360941eb 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + WHERE NOT booking__is_instant + ) subq_13 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_17 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql index 09af3a3c27..b83572690f 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio + subq_15.metric_time__day + , CAST(subq_15.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_15.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_14.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_8.metric_time__day + , subq_8.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_7.metric_time__day + , SUM(subq_7.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_6.metric_time__day + , subq_6.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 + subq_7.metric_time__day + ) subq_8 + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_13.metric_time__day + , subq_13.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.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_8.metric_time__day - , subq_8.booking_value + subq_11.metric_time__day + , subq_11.booking_value 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.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.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.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_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 @@ -446,15 +549,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_7 - ) subq_8 - ) subq_9 + ) subq_10 + ) subq_11 + ) subq_12 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_12.metric_time__day + ) subq_13 + ) subq_14 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_9.metric_time__day = subq_14.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql index a465dac6f6..b3f811ac19 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_28.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_28 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_23.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0.sql index 73954cba02..bb5826ee1e 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_9.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_8.metric_time__day + , subq_8.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE NOT booking__is_instant + ) subq_4 + ) subq_5 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_7.metric_time__day + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..31360941eb 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + WHERE NOT booking__is_instant + ) subq_13 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_17 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql index d757f7bc0b..8df9db1cbe 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,462 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio + subq_15.metric_time__day + , CAST(subq_15.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_15.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) AS metric_time__day + , MAX(subq_9.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_14.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_8.metric_time__day + , subq_8.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_7.metric_time__day + , SUM(subq_7.booking_value) AS booking_value FROM ( -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_6.metric_time__day + , subq_6.booking_value FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.booking_value FROM ( -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 + subq_7.metric_time__day + ) subq_8 + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.booking_value + subq_13.metric_time__day + , subq_13.booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.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_8.metric_time__day - , subq_8.booking_value + subq_11.metric_time__day + , subq_11.booking_value 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.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.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.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_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 @@ -446,15 +549,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_7 - ) subq_8 - ) subq_9 + ) subq_10 + ) subq_11 + ) subq_12 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_12.metric_time__day + ) subq_13 + ) subq_14 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_9.metric_time__day = subq_14.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_9.metric_time__day, subq_14.metric_time__day) +) subq_15 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql index a465dac6f6..b3f811ac19 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_23.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_28.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -17,19 +17,27 @@ FROM ( metric_time__day , SUM(booking_value) AS booking_value_with_is_instant_constraint FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant + metric_time__day + , booking__is_instant , booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_17 + WHERE booking__is_instant + ) subq_19 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_23 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +50,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_28 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_23.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_23.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql index fa133adf99..70a6055760 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,337 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_9.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_8.metric_time__day + , subq_8.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE NOT booking__is_instant + ) subq_4 + ) subq_5 WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_7.metric_time__day + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..31360941eb 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -11,16 +11,24 @@ FROM ( metric_time__day , SUM(bookings) AS delayed_bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + WHERE NOT booking__is_instant + ) subq_13 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_17 diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml index 25dd48aa97..99eaf6a620 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfp_0.xml @@ -46,7 +46,7 @@ - + @@ -86,16 +86,47 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml index c85ce86aca..8201ad4a73 100644 --- a/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml +++ b/tests_metricflow/snapshots/test_source_scan_optimizer.py/DataflowPlan/test_constrained_metric_not_combined__dfpo_0.xml @@ -46,7 +46,7 @@ - + @@ -86,16 +86,47 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 75603754c5..077d44257f 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 @@ -1,242 +1,345 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_11.metric_time__day + , COALESCE(subq_11.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day - , subq_5.bookings AS bookings + subq_9.metric_time__day AS metric_time__day + , subq_8.bookings AS bookings FROM ( -- Time Spine SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_10.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_10 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY metric_time__day - ) subq_5 + ) subq_8 ON - subq_6.metric_time__day = subq_5.metric_time__day -) subq_8 + subq_9.metric_time__day = subq_8.metric_time__day +) subq_11 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 4ecdfebc25..20e918f6ae 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_16.ds AS metric_time__day - , subq_14.bookings AS bookings - FROM ***************************.mf_time_spine subq_16 + subq_20.ds AS metric_time__day + , subq_18.bookings AS bookings + FROM ***************************.mf_time_spine subq_20 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -16,19 +16,27 @@ FROM ( metric_time__day , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATETIME_TRUNC(ds, day) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATETIME_TRUNC(ds, day) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_14 + ) subq_18 ON - subq_16.ds = subq_14.metric_time__day -) subq_17 + subq_20.ds = subq_18.metric_time__day +) subq_21 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 7945e559e4..97202fe9e5 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 @@ -1,248 +1,351 @@ -- 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_11.metric_time__day + , subq_11.booking__is_instant + , COALESCE(subq_11.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_10.metric_time__day + , subq_10.booking__is_instant + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.booking__is_instant AS booking__is_instant - , subq_4.bookings AS bookings + subq_8.metric_time__day AS metric_time__day + , subq_7.booking__is_instant AS booking__is_instant + , subq_7.bookings AS bookings FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_9.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_9 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , subq_3.booking__is_instant - , SUM(subq_3.bookings) AS bookings + subq_6.metric_time__day + , subq_6.booking__is_instant + , SUM(subq_6.bookings) AS bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 + ) subq_6 GROUP BY metric_time__day , booking__is_instant - ) subq_4 + ) subq_7 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_8.metric_time__day = subq_7.metric_time__day + ) subq_10 WHERE booking__is_instant -) subq_8 +) subq_11 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 2b1b12de20..0999c11daa 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 @@ -12,10 +12,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 + subq_19.ds AS metric_time__day + , subq_17.booking__is_instant AS booking__is_instant + , subq_17.bookings AS bookings + FROM ***************************.mf_time_spine subq_19 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Aggregate Measures @@ -24,22 +24,30 @@ FROM ( , booking__is_instant , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATETIME_TRUNC(ds, day) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATETIME_TRUNC(ds, day) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_17 ON - subq_15.ds = subq_13.metric_time__day - ) subq_16 + subq_19.ds = subq_17.metric_time__day + ) subq_20 WHERE booking__is_instant -) subq_17 +) subq_21 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 10d71d6f54..c6a4a763f6 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 @@ -1,242 +1,345 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_11.metric_time__day + , COALESCE(subq_11.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day - , subq_5.bookings AS bookings + subq_9.metric_time__day AS metric_time__day + , subq_8.bookings AS bookings FROM ( -- Time Spine SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_10.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_10 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 + subq_7.metric_time__day + ) subq_8 ON - subq_6.metric_time__day = subq_5.metric_time__day -) subq_8 + subq_9.metric_time__day = subq_8.metric_time__day +) subq_11 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 1185bf668d..937c857812 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_16.ds AS metric_time__day - , subq_14.bookings AS bookings - FROM ***************************.mf_time_spine subq_16 + subq_20.ds AS metric_time__day + , subq_18.bookings AS bookings + FROM ***************************.mf_time_spine subq_20 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -16,19 +16,27 @@ FROM ( metric_time__day , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_14 + ) subq_18 ON - subq_16.ds = subq_14.metric_time__day -) subq_17 + subq_20.ds = subq_18.metric_time__day +) subq_21 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 d60f9f75b1..5d08b97f19 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 @@ -1,248 +1,351 @@ -- 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_11.metric_time__day + , subq_11.booking__is_instant + , COALESCE(subq_11.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_10.metric_time__day + , subq_10.booking__is_instant + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.booking__is_instant AS booking__is_instant - , subq_4.bookings AS bookings + subq_8.metric_time__day AS metric_time__day + , subq_7.booking__is_instant AS booking__is_instant + , subq_7.bookings AS bookings FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_9.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_9 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , subq_3.booking__is_instant - , SUM(subq_3.bookings) AS bookings + subq_6.metric_time__day + , subq_6.booking__is_instant + , SUM(subq_6.bookings) AS bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 + ) subq_6 GROUP BY - subq_3.metric_time__day - , subq_3.booking__is_instant - ) subq_4 + subq_6.metric_time__day + , subq_6.booking__is_instant + ) subq_7 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_8.metric_time__day = subq_7.metric_time__day + ) subq_10 WHERE booking__is_instant -) subq_8 +) subq_11 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 476eccde2c..b77531128d 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 @@ -12,10 +12,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 + subq_19.ds AS metric_time__day + , subq_17.booking__is_instant AS booking__is_instant + , subq_17.bookings AS bookings + FROM ***************************.mf_time_spine subq_19 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Aggregate Measures @@ -24,22 +24,30 @@ FROM ( , booking__is_instant , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_17 ON - subq_15.ds = subq_13.metric_time__day - ) subq_16 + subq_19.ds = subq_17.metric_time__day + ) subq_20 WHERE booking__is_instant -) subq_17 +) subq_21 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0.sql index a39da38b06..077b8a4c94 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 @@ -1,242 +1,345 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_11.metric_time__day + , COALESCE(subq_11.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day - , subq_5.bookings AS bookings + subq_9.metric_time__day AS metric_time__day + , subq_8.bookings AS bookings FROM ( -- Time Spine SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_10.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_10 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 + subq_7.metric_time__day + ) subq_8 ON - subq_6.metric_time__day = subq_5.metric_time__day -) subq_8 + subq_9.metric_time__day = subq_8.metric_time__day +) subq_11 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 1185bf668d..937c857812 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_filter__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_16.ds AS metric_time__day - , subq_14.bookings AS bookings - FROM ***************************.mf_time_spine subq_16 + subq_20.ds AS metric_time__day + , subq_18.bookings AS bookings + FROM ***************************.mf_time_spine subq_20 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -16,19 +16,27 @@ FROM ( metric_time__day , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_14 + ) subq_18 ON - subq_16.ds = subq_14.metric_time__day -) subq_17 + subq_20.ds = subq_18.metric_time__day +) subq_21 diff --git a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0.sql index ed0bc69197..fe5d8ea8c7 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 @@ -1,248 +1,351 @@ -- 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_11.metric_time__day + , subq_11.booking__is_instant + , COALESCE(subq_11.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_10.metric_time__day + , subq_10.booking__is_instant + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.booking__is_instant AS booking__is_instant - , subq_4.bookings AS bookings + subq_8.metric_time__day AS metric_time__day + , subq_7.booking__is_instant AS booking__is_instant + , subq_7.bookings AS bookings FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_9.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_9 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , subq_3.booking__is_instant - , SUM(subq_3.bookings) AS bookings + subq_6.metric_time__day + , subq_6.booking__is_instant + , SUM(subq_6.bookings) AS bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 + ) subq_6 GROUP BY - subq_3.metric_time__day - , subq_3.booking__is_instant - ) subq_4 + subq_6.metric_time__day + , subq_6.booking__is_instant + ) subq_7 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_8.metric_time__day = subq_7.metric_time__day + ) subq_10 WHERE booking__is_instant -) subq_8 +) subq_11 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 476eccde2c..b77531128d 100644 --- a/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/DuckDB/test_simple_join_to_time_spine_with_queried_filter__plan0_optimized.sql @@ -12,10 +12,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 + subq_19.ds AS metric_time__day + , subq_17.booking__is_instant AS booking__is_instant + , subq_17.bookings AS bookings + FROM ***************************.mf_time_spine subq_19 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Aggregate Measures @@ -24,22 +24,30 @@ FROM ( , booking__is_instant , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_17 ON - subq_15.ds = subq_13.metric_time__day - ) subq_16 + subq_19.ds = subq_17.metric_time__day + ) subq_20 WHERE booking__is_instant -) subq_17 +) subq_21 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 a39da38b06..077b8a4c94 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 @@ -1,242 +1,345 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_11.metric_time__day + , COALESCE(subq_11.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day - , subq_5.bookings AS bookings + subq_9.metric_time__day AS metric_time__day + , subq_8.bookings AS bookings FROM ( -- Time Spine SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_10.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_10 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 + subq_7.metric_time__day + ) subq_8 ON - subq_6.metric_time__day = subq_5.metric_time__day -) subq_8 + subq_9.metric_time__day = subq_8.metric_time__day +) subq_11 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 1185bf668d..937c857812 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_16.ds AS metric_time__day - , subq_14.bookings AS bookings - FROM ***************************.mf_time_spine subq_16 + subq_20.ds AS metric_time__day + , subq_18.bookings AS bookings + FROM ***************************.mf_time_spine subq_20 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -16,19 +16,27 @@ FROM ( metric_time__day , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_14 + ) subq_18 ON - subq_16.ds = subq_14.metric_time__day -) subq_17 + subq_20.ds = subq_18.metric_time__day +) subq_21 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 ed0bc69197..fe5d8ea8c7 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 @@ -1,248 +1,351 @@ -- 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_11.metric_time__day + , subq_11.booking__is_instant + , COALESCE(subq_11.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_10.metric_time__day + , subq_10.booking__is_instant + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.booking__is_instant AS booking__is_instant - , subq_4.bookings AS bookings + subq_8.metric_time__day AS metric_time__day + , subq_7.booking__is_instant AS booking__is_instant + , subq_7.bookings AS bookings FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_9.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_9 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , subq_3.booking__is_instant - , SUM(subq_3.bookings) AS bookings + subq_6.metric_time__day + , subq_6.booking__is_instant + , SUM(subq_6.bookings) AS bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 + ) subq_6 GROUP BY - subq_3.metric_time__day - , subq_3.booking__is_instant - ) subq_4 + subq_6.metric_time__day + , subq_6.booking__is_instant + ) subq_7 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_8.metric_time__day = subq_7.metric_time__day + ) subq_10 WHERE booking__is_instant -) subq_8 +) subq_11 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 476eccde2c..b77531128d 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 @@ -12,10 +12,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 + subq_19.ds AS metric_time__day + , subq_17.booking__is_instant AS booking__is_instant + , subq_17.bookings AS bookings + FROM ***************************.mf_time_spine subq_19 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Aggregate Measures @@ -24,22 +24,30 @@ FROM ( , booking__is_instant , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_17 ON - subq_15.ds = subq_13.metric_time__day - ) subq_16 + subq_19.ds = subq_17.metric_time__day + ) subq_20 WHERE booking__is_instant -) subq_17 +) subq_21 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 fbbca501a8..98806a7229 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 @@ -1,242 +1,345 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_11.metric_time__day + , COALESCE(subq_11.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day - , subq_5.bookings AS bookings + subq_9.metric_time__day AS metric_time__day + , subq_8.bookings AS bookings FROM ( -- Time Spine SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_10.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_10 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 + subq_7.metric_time__day + ) subq_8 ON - subq_6.metric_time__day = subq_5.metric_time__day -) subq_8 + subq_9.metric_time__day = subq_8.metric_time__day +) subq_11 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 1185bf668d..937c857812 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_16.ds AS metric_time__day - , subq_14.bookings AS bookings - FROM ***************************.mf_time_spine subq_16 + subq_20.ds AS metric_time__day + , subq_18.bookings AS bookings + FROM ***************************.mf_time_spine subq_20 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -16,19 +16,27 @@ FROM ( metric_time__day , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_14 + ) subq_18 ON - subq_16.ds = subq_14.metric_time__day -) subq_17 + subq_20.ds = subq_18.metric_time__day +) subq_21 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 53e30fb806..f88ef62297 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 @@ -1,248 +1,351 @@ -- 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_11.metric_time__day + , subq_11.booking__is_instant + , COALESCE(subq_11.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_10.metric_time__day + , subq_10.booking__is_instant + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.booking__is_instant AS booking__is_instant - , subq_4.bookings AS bookings + subq_8.metric_time__day AS metric_time__day + , subq_7.booking__is_instant AS booking__is_instant + , subq_7.bookings AS bookings FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_9.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_9 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , subq_3.booking__is_instant - , SUM(subq_3.bookings) AS bookings + subq_6.metric_time__day + , subq_6.booking__is_instant + , SUM(subq_6.bookings) AS bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 + ) subq_6 GROUP BY - subq_3.metric_time__day - , subq_3.booking__is_instant - ) subq_4 + subq_6.metric_time__day + , subq_6.booking__is_instant + ) subq_7 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_8.metric_time__day = subq_7.metric_time__day + ) subq_10 WHERE booking__is_instant -) subq_8 +) subq_11 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 476eccde2c..b77531128d 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 @@ -12,10 +12,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 + subq_19.ds AS metric_time__day + , subq_17.booking__is_instant AS booking__is_instant + , subq_17.bookings AS bookings + FROM ***************************.mf_time_spine subq_19 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Aggregate Measures @@ -24,22 +24,30 @@ FROM ( , booking__is_instant , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_17 ON - subq_15.ds = subq_13.metric_time__day - ) subq_16 + subq_19.ds = subq_17.metric_time__day + ) subq_20 WHERE booking__is_instant -) subq_17 +) subq_21 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 1841f75d94..4faadd5042 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 @@ -1,242 +1,345 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_11.metric_time__day + , COALESCE(subq_11.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day - , subq_5.bookings AS bookings + subq_9.metric_time__day AS metric_time__day + , subq_8.bookings AS bookings FROM ( -- Time Spine SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_10.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_10 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 + subq_7.metric_time__day + ) subq_8 ON - subq_6.metric_time__day = subq_5.metric_time__day -) subq_8 + subq_9.metric_time__day = subq_8.metric_time__day +) subq_11 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 1185bf668d..937c857812 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_16.ds AS metric_time__day - , subq_14.bookings AS bookings - FROM ***************************.mf_time_spine subq_16 + subq_20.ds AS metric_time__day + , subq_18.bookings AS bookings + FROM ***************************.mf_time_spine subq_20 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -16,19 +16,27 @@ FROM ( metric_time__day , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_14 + ) subq_18 ON - subq_16.ds = subq_14.metric_time__day -) subq_17 + subq_20.ds = subq_18.metric_time__day +) subq_21 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 06ba1452be..cd695ffcf8 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 @@ -1,248 +1,351 @@ -- 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_11.metric_time__day + , subq_11.booking__is_instant + , COALESCE(subq_11.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_10.metric_time__day + , subq_10.booking__is_instant + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.booking__is_instant AS booking__is_instant - , subq_4.bookings AS bookings + subq_8.metric_time__day AS metric_time__day + , subq_7.booking__is_instant AS booking__is_instant + , subq_7.bookings AS bookings FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_9.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_9 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , subq_3.booking__is_instant - , SUM(subq_3.bookings) AS bookings + subq_6.metric_time__day + , subq_6.booking__is_instant + , SUM(subq_6.bookings) AS bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 + ) subq_6 GROUP BY - subq_3.metric_time__day - , subq_3.booking__is_instant - ) subq_4 + subq_6.metric_time__day + , subq_6.booking__is_instant + ) subq_7 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_8.metric_time__day = subq_7.metric_time__day + ) subq_10 WHERE booking__is_instant -) subq_8 +) subq_11 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 476eccde2c..b77531128d 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 @@ -12,10 +12,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 + subq_19.ds AS metric_time__day + , subq_17.booking__is_instant AS booking__is_instant + , subq_17.bookings AS bookings + FROM ***************************.mf_time_spine subq_19 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Aggregate Measures @@ -24,22 +24,30 @@ FROM ( , booking__is_instant , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_17 ON - subq_15.ds = subq_13.metric_time__day - ) subq_16 + subq_19.ds = subq_17.metric_time__day + ) subq_20 WHERE booking__is_instant -) subq_17 +) subq_21 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 6c43edefe6..666b0545f3 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 @@ -1,242 +1,345 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_11.metric_time__day + , COALESCE(subq_11.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day - , subq_5.bookings AS bookings + subq_9.metric_time__day AS metric_time__day + , subq_8.bookings AS bookings FROM ( -- Time Spine SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_10.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_10 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_7.metric_time__day + , SUM(subq_7.bookings) AS bookings FROM ( -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 - ) subq_4 + ) subq_6 + ) subq_7 GROUP BY - subq_4.metric_time__day - ) subq_5 + subq_7.metric_time__day + ) subq_8 ON - subq_6.metric_time__day = subq_5.metric_time__day -) subq_8 + subq_9.metric_time__day = subq_8.metric_time__day +) subq_11 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 1185bf668d..937c857812 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_16.ds AS metric_time__day - , subq_14.bookings AS bookings - FROM ***************************.mf_time_spine subq_16 + subq_20.ds AS metric_time__day + , subq_18.bookings AS bookings + FROM ***************************.mf_time_spine subq_20 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -16,19 +16,27 @@ FROM ( metric_time__day , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_14 + ) subq_18 ON - subq_16.ds = subq_14.metric_time__day -) subq_17 + subq_20.ds = subq_18.metric_time__day +) subq_21 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 7fe5de84a9..224e31010d 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 @@ -1,248 +1,351 @@ -- 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_11.metric_time__day + , subq_11.booking__is_instant + , COALESCE(subq_11.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_10.metric_time__day + , subq_10.booking__is_instant + , subq_10.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.booking__is_instant AS booking__is_instant - , subq_4.bookings AS bookings + subq_8.metric_time__day AS metric_time__day + , subq_7.booking__is_instant AS booking__is_instant + , subq_7.bookings AS bookings FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_9.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_9 + ) subq_8 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , subq_3.booking__is_instant - , SUM(subq_3.bookings) AS bookings + subq_6.metric_time__day + , subq_6.booking__is_instant + , SUM(subq_6.bookings) AS bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.ds_partitioned__day + , subq_3.ds_partitioned__week + , subq_3.ds_partitioned__month + , subq_3.ds_partitioned__quarter + , subq_3.ds_partitioned__year + , subq_3.ds_partitioned__extract_year + , subq_3.ds_partitioned__extract_quarter + , subq_3.ds_partitioned__extract_month + , subq_3.ds_partitioned__extract_day + , subq_3.ds_partitioned__extract_dow + , subq_3.ds_partitioned__extract_doy + , subq_3.paid_at__day + , subq_3.paid_at__week + , subq_3.paid_at__month + , subq_3.paid_at__quarter + , subq_3.paid_at__year + , subq_3.paid_at__extract_year + , subq_3.paid_at__extract_quarter + , subq_3.paid_at__extract_month + , subq_3.paid_at__extract_day + , subq_3.paid_at__extract_dow + , subq_3.paid_at__extract_doy + , subq_3.booking__ds__day + , subq_3.booking__ds__week + , subq_3.booking__ds__month + , subq_3.booking__ds__quarter + , subq_3.booking__ds__year + , subq_3.booking__ds__extract_year + , subq_3.booking__ds__extract_quarter + , subq_3.booking__ds__extract_month + , subq_3.booking__ds__extract_day + , subq_3.booking__ds__extract_dow + , subq_3.booking__ds__extract_doy + , subq_3.booking__ds_partitioned__day + , subq_3.booking__ds_partitioned__week + , subq_3.booking__ds_partitioned__month + , subq_3.booking__ds_partitioned__quarter + , subq_3.booking__ds_partitioned__year + , subq_3.booking__ds_partitioned__extract_year + , subq_3.booking__ds_partitioned__extract_quarter + , subq_3.booking__ds_partitioned__extract_month + , subq_3.booking__ds_partitioned__extract_day + , subq_3.booking__ds_partitioned__extract_dow + , subq_3.booking__ds_partitioned__extract_doy + , subq_3.booking__paid_at__day + , subq_3.booking__paid_at__week + , subq_3.booking__paid_at__month + , subq_3.booking__paid_at__quarter + , subq_3.booking__paid_at__year + , subq_3.booking__paid_at__extract_year + , subq_3.booking__paid_at__extract_quarter + , subq_3.booking__paid_at__extract_month + , subq_3.booking__paid_at__extract_day + , subq_3.booking__paid_at__extract_dow + , subq_3.booking__paid_at__extract_doy + , subq_3.metric_time__day + , subq_3.metric_time__week + , subq_3.metric_time__month + , subq_3.metric_time__quarter + , subq_3.metric_time__year + , subq_3.metric_time__extract_year + , subq_3.metric_time__extract_quarter + , subq_3.metric_time__extract_month + , subq_3.metric_time__extract_day + , subq_3.metric_time__extract_dow + , subq_3.metric_time__extract_doy + , subq_3.listing + , subq_3.guest + , subq_3.host + , subq_3.booking__listing + , subq_3.booking__guest + , subq_3.booking__host + , subq_3.is_instant + , subq_3.booking__is_instant + , subq_3.bookings + , subq_3.instant_bookings + , subq_3.booking_value + , subq_3.max_booking_value + , subq_3.min_booking_value + , subq_3.bookers + , subq_3.average_booking_value + , subq_3.referred_bookings + , subq_3.median_booking_value + , subq_3.booking_value_p99 + , subq_3.discrete_booking_value_p99 + , subq_3.approximate_continuous_booking_value_p99 + , subq_3.approximate_discrete_booking_value_p99 FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' 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 - ) subq_1 - ) subq_2 + 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.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS 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 ( + -- 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_2 + ) subq_3 + WHERE booking__is_instant + ) subq_4 + ) subq_5 WHERE booking__is_instant - ) subq_3 + ) subq_6 GROUP BY - subq_3.metric_time__day - , subq_3.booking__is_instant - ) subq_4 + subq_6.metric_time__day + , subq_6.booking__is_instant + ) subq_7 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_8.metric_time__day = subq_7.metric_time__day + ) subq_10 WHERE booking__is_instant -) subq_8 +) subq_11 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 476eccde2c..b77531128d 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 @@ -12,10 +12,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 + subq_19.ds AS metric_time__day + , subq_17.booking__is_instant AS booking__is_instant + , subq_17.bookings AS bookings + FROM ***************************.mf_time_spine subq_19 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Aggregate Measures @@ -24,22 +24,30 @@ FROM ( , booking__is_instant , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , is_instant AS booking__is_instant - , 1 AS bookings - FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + metric_time__day + , booking__is_instant + , bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , is_instant AS booking__is_instant + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_13 + WHERE booking__is_instant + ) subq_15 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_17 ON - subq_15.ds = subq_13.metric_time__day - ) subq_16 + subq_19.ds = subq_17.metric_time__day + ) subq_20 WHERE booking__is_instant -) subq_17 +) subq_21