diff --git a/metricflow-semantics/metricflow_semantics/specs/linkable_spec_set.py b/metricflow-semantics/metricflow_semantics/specs/linkable_spec_set.py
index 40cc5fe81..183a02ed2 100644
--- a/metricflow-semantics/metricflow_semantics/specs/linkable_spec_set.py
+++ b/metricflow-semantics/metricflow_semantics/specs/linkable_spec_set.py
@@ -40,6 +40,11 @@ def contains_metric_time(self) -> bool:
"""Returns true if this set contains a spec referring to metric time at any grain."""
return len(self.metric_time_specs) > 0
+ @property
+ def contains_only_metric_time(self) -> bool:
+ """If all specs are metric_time specs, return True.."""
+ return set(self.metric_time_specs) == set(self.as_tuple)
+
@property
def time_dimension_specs_with_custom_grain(self) -> Tuple[TimeDimensionSpec, ...]: # noqa: D102
return tuple([spec for spec in self.time_dimension_specs if spec.time_granularity.is_custom_granularity])
diff --git a/metricflow-semantics/metricflow_semantics/specs/metric_spec.py b/metricflow-semantics/metricflow_semantics/specs/metric_spec.py
index 3e0d21a35..d35851493 100644
--- a/metricflow-semantics/metricflow_semantics/specs/metric_spec.py
+++ b/metricflow-semantics/metricflow_semantics/specs/metric_spec.py
@@ -49,3 +49,13 @@ def has_time_offset(self) -> bool: # noqa: D102
def without_offset(self) -> MetricSpec:
"""Represents the metric spec with any time offsets removed."""
return MetricSpec(element_name=self.element_name, filter_spec_set=self.filter_spec_set, alias=self.alias)
+
+ def with_new_filter_spec_set(self, new_filter_spec_set: WhereFilterSpecSet) -> MetricSpec:
+ """Represents the metric spec with a new filter spec set."""
+ return MetricSpec(
+ element_name=self.element_name,
+ filter_spec_set=new_filter_spec_set,
+ alias=self.alias,
+ offset_window=self.offset_window,
+ offset_to_grain=self.offset_to_grain,
+ )
diff --git a/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_spec_set.py b/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_spec_set.py
index 8e039c534..3318e14b7 100644
--- a/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_spec_set.py
+++ b/metricflow-semantics/metricflow_semantics/specs/where_filter/where_filter_spec_set.py
@@ -44,3 +44,13 @@ def merge(self, other: WhereFilterSpecSet) -> WhereFilterSpecSet:
metric_level_filter_specs=self.metric_level_filter_specs + other.metric_level_filter_specs,
query_level_filter_specs=self.query_level_filter_specs + other.query_level_filter_specs,
)
+
+ def replace_query_level_filter_specs(
+ self, new_query_level_filter_specs: Tuple[WhereFilterSpec, ...]
+ ) -> WhereFilterSpecSet:
+ """Return the same set but with the query level filter specs replaced."""
+ return WhereFilterSpecSet(
+ measure_level_filter_specs=self.measure_level_filter_specs,
+ metric_level_filter_specs=self.metric_level_filter_specs,
+ query_level_filter_specs=new_query_level_filter_specs,
+ )
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 fe28fb047..9d9b0594f 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
@@ -495,7 +495,7 @@ metric:
metric:
name: "bookings_growth_since_start_of_month"
description: |
- percentage growth of bookings since the start of the month,
+ number of bookings since the start of the month,
used to test derived metrics with an offset_to_grain.
type: derived
type_params:
@@ -506,6 +506,24 @@ metric:
offset_to_grain: month
alias: bookings_at_start_of_month
---
+metric:
+ name: bookings_offset_to_grain_twice_with_tiered_filters
+ description: tests a nested offset_to_grain metric with filters at each level
+ type: derived
+ type_params:
+ expr: bookings_this_month_wtd - bookings
+ metrics:
+ - name: bookings
+ - name: bookings_growth_since_start_of_month
+ offset_to_grain: week
+ alias: bookings_this_month_wtd
+ filter:
+ - "{{ TimeDimension('booking__ds', 'year') }} >= '2019-01-01'"
+ - "{{ TimeDimension('listing__created_at', 'day') }} >= '2020-01-02'"
+ filter:
+ - "{{ TimeDimension('metric_time', 'month') }} >= '2020-01-01'"
+ - "{{ Dimension('booking__is_instant') }}"
+---
metric:
name: "bookings_month_start_compared_to_1_month_prior"
description: |
@@ -700,7 +718,7 @@ metric:
alias: bookings_2_weeks_ago
---
metric:
- name: "bookings_offset_once"
+ name: bookings_offset_once
description: bookings metric offset once.
type: derived
type_params:
@@ -710,7 +728,7 @@ metric:
offset_window: 5 days
---
metric:
- name: "bookings_offset_twice"
+ name: bookings_offset_twice
description: bookings metric offset twice.
type: derived
type_params:
@@ -719,6 +737,22 @@ metric:
- name: bookings_offset_once
offset_window: 2 days
---
+metric:
+ name: bookings_offset_twice_with_tiered_filters
+ description: bookings metric offset twice with tiered filters
+ type: derived
+ type_params:
+ expr: bookings_offset_once
+ metrics:
+ - name: bookings_offset_once
+ offset_window: 1 month
+ filter:
+ - "{{ TimeDimension('metric_time', 'month') }} >= '2019-12-01'"
+ - "{{ Dimension('booking__is_instant') }}"
+ filter:
+ - "{{ TimeDimension('metric_time', 'year') }} >= '2019-01-01'"
+ - "{{ Entity('listing') }} IS NOT NULL"
+---
metric:
name: bookings_at_start_of_month
description: |
diff --git a/metricflow/dataflow/builder/builder_cache.py b/metricflow/dataflow/builder/builder_cache.py
index 79444561a..403e0fe34 100644
--- a/metricflow/dataflow/builder/builder_cache.py
+++ b/metricflow/dataflow/builder/builder_cache.py
@@ -1,11 +1,12 @@
from __future__ import annotations
from dataclasses import dataclass
-from typing import Optional
+from typing import Optional, Sequence
from metricflow_semantics.collection_helpers.lru_cache import LruCache
from metricflow_semantics.specs.linkable_spec_set import LinkableSpecSet
from metricflow_semantics.specs.metric_spec import MetricSpec
+from metricflow_semantics.specs.where_filter.where_filter_spec import WhereFilterSpec
from metricflow_semantics.specs.where_filter.where_filter_transform import WhereSpecFactory
from metricflow.dataflow.builder.measure_spec_properties import MeasureSpecProperties
@@ -39,6 +40,7 @@ class BuildAnyMetricOutputNodeParameterSet:
filter_spec_factory: WhereSpecFactory
predicate_pushdown_state: PredicatePushdownState
for_group_by_source_node: bool
+ time_spine_filter_specs: Sequence[WhereFilterSpec] = ()
class DataflowPlanBuilderCache:
diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py
index c7cdc5ebb..68d629056 100644
--- a/metricflow/dataflow/builder/dataflow_plan_builder.py
+++ b/metricflow/dataflow/builder/dataflow_plan_builder.py
@@ -245,6 +245,7 @@ def _build_aggregated_conversion_node(
window: Optional[MetricTimeWindow],
queried_linkable_specs: LinkableSpecSet,
predicate_pushdown_state: PredicatePushdownState,
+ time_spine_filter_specs: Sequence[WhereFilterSpec] = (),
constant_properties: Optional[Sequence[ConstantPropertyInput]] = None,
) -> DataflowPlanNode:
"""Builds a node that contains aggregated values of conversions and opportunities."""
@@ -296,6 +297,7 @@ def _build_aggregated_conversion_node(
metric_input_measure_spec=base_measure_spec,
queried_linkable_specs=queried_linkable_specs,
predicate_pushdown_state=time_range_only_pushdown_state,
+ time_spine_filter_specs=time_spine_filter_specs,
)
# Build unaggregated conversions source node
@@ -371,6 +373,7 @@ def _build_aggregated_conversion_node(
queried_linkable_specs=queried_linkable_specs,
predicate_pushdown_state=disabled_pushdown_state,
measure_recipe=recipe_with_join_conversion_source_node,
+ time_spine_filter_specs=time_spine_filter_specs,
)
# Combine the aggregated opportunities and conversion data sets
@@ -384,6 +387,7 @@ def _build_conversion_metric_output_node(
queried_linkable_specs: LinkableSpecSet,
filter_spec_factory: WhereSpecFactory,
predicate_pushdown_state: PredicatePushdownState,
+ time_spine_filter_specs: Sequence[WhereFilterSpec] = (),
for_group_by_source_node: bool = False,
) -> ComputeMetricsNode:
"""Builds a compute metric node for a conversion metric."""
@@ -427,6 +431,7 @@ def _build_conversion_metric_output_node(
entity_spec=entity_spec,
window=conversion_type_params.window,
constant_properties=conversion_type_params.constant_properties,
+ time_spine_filter_specs=time_spine_filter_specs,
)
return self.build_computed_metrics_node(
@@ -442,6 +447,7 @@ def _build_cumulative_metric_output_node(
queried_linkable_specs: LinkableSpecSet,
filter_spec_factory: WhereSpecFactory,
predicate_pushdown_state: PredicatePushdownState,
+ time_spine_filter_specs: Sequence[WhereFilterSpec] = (),
for_group_by_source_node: bool = False,
) -> DataflowPlanNode:
# TODO: [custom granularity] Figure out how to support custom granularities as defaults
@@ -465,6 +471,7 @@ def _build_cumulative_metric_output_node(
filter_spec_factory=filter_spec_factory,
predicate_pushdown_state=predicate_pushdown_state,
for_group_by_source_node=for_group_by_source_node,
+ time_spine_filter_specs=time_spine_filter_specs,
)
# If a cumulative metric is queried without default granularity, it will need to be aggregated twice -
@@ -495,6 +502,7 @@ def _build_base_metric_output_node(
queried_linkable_specs: LinkableSpecSet,
filter_spec_factory: WhereSpecFactory,
predicate_pushdown_state: PredicatePushdownState,
+ time_spine_filter_specs: Sequence[WhereFilterSpec] = (),
for_group_by_source_node: bool = False,
) -> ComputeMetricsNode:
"""Builds a node to compute a metric that is not defined from other metrics."""
@@ -549,6 +557,7 @@ def _build_base_metric_output_node(
metric_input_measure_spec=metric_input_measure_spec,
queried_linkable_specs=queried_linkable_specs,
predicate_pushdown_state=predicate_pushdown_state,
+ time_spine_filter_specs=time_spine_filter_specs,
)
return self.build_computed_metrics_node(
metric_spec=metric_spec,
@@ -563,73 +572,57 @@ def _build_derived_metric_output_node(
queried_linkable_specs: LinkableSpecSet,
filter_spec_factory: WhereSpecFactory,
predicate_pushdown_state: PredicatePushdownState,
+ time_spine_filter_specs: Sequence[WhereFilterSpec] = (),
for_group_by_source_node: bool = False,
) -> DataflowPlanNode:
"""Builds a node to compute a metric defined from other metrics."""
- metric = self._metric_lookup.get_metric(metric_spec.reference)
- metric_input_specs = self._build_input_metric_specs_for_derived_metric(
- metric_reference=metric_spec.reference,
- filter_spec_factory=filter_spec_factory,
+ input_metric_specs = self._build_input_metric_specs(
+ metric_spec=metric_spec, filter_spec_factory=filter_spec_factory
)
logger.debug(
LazyFormat(
- lambda: f"For {metric.type} metric: {metric_spec}, needed metrics are:\n"
- f"{mf_pformat(metric_input_specs)}"
+ lambda: f"For derived metric {metric_spec}, needed metrics are:\n" f"{mf_pformat(input_metric_specs)}"
)
)
-
- required_linkable_specs = self.__get_required_linkable_specs(
- queried_linkable_specs=queried_linkable_specs, filter_specs=metric_spec.filter_spec_set.all_filter_specs
+ # Pushdown is disabled for offset metrics; we can't apply filters to the source node due to potential changes from the offset.
+ metric_pushdown_state = (
+ PredicatePushdownState.with_pushdown_disabled() if metric_spec.has_time_offset else predicate_pushdown_state
)
parent_nodes: List[DataflowPlanNode] = []
-
- # This is the filter that's defined for the metric in the configs.
- metric_definition_filter_specs = filter_spec_factory.create_from_where_filter_intersection(
- filter_location=WhereFilterLocation.for_metric(metric_spec.reference),
- filter_intersection=metric.filter,
- )
-
- for metric_input_spec in metric_input_specs:
- where_filter_spec_set = WhereFilterSpecSet(
- metric_level_filter_specs=tuple(metric_definition_filter_specs),
- )
-
- # These are the filters that's defined as part of the input metric.
- where_filter_spec_set = where_filter_spec_set.merge(metric_input_spec.filter_spec_set)
-
- # 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:
- where_filter_spec_set = where_filter_spec_set.merge(metric_spec.filter_spec_set)
- metric_pushdown_state = (
- predicate_pushdown_state
- if not metric_spec.has_time_offset
- else PredicatePushdownState.with_pushdown_disabled()
- )
-
- parent_nodes.append(
- self._build_any_metric_output_node(
- BuildAnyMetricOutputNodeParameterSet(
- metric_spec=MetricSpec(
- element_name=metric_input_spec.element_name,
- filter_spec_set=where_filter_spec_set,
- alias=metric_input_spec.alias,
- offset_window=metric_input_spec.offset_window,
- offset_to_grain=metric_input_spec.offset_to_grain,
- ),
- queried_linkable_specs=(
- queried_linkable_specs if not metric_spec.has_time_offset else required_linkable_specs
- ),
- filter_spec_factory=filter_spec_factory,
- predicate_pushdown_state=metric_pushdown_state,
- for_group_by_source_node=False,
+ for input_metric_spec in input_metric_specs:
+ # If the metric has a time offset, we'll apply any query-level metric_time constraints after the offset because
+ # those values may have changed. Time constraints will be applied by INNER JOINing to time spine.
+ input_metric_filter_set = input_metric_spec.filter_spec_set
+ query_level_agg_time_filter_specs: Tuple[WhereFilterSpec, ...] = ()
+ if input_metric_spec.has_time_offset:
+ query_level_non_agg_time_filter_specs: Tuple[WhereFilterSpec, ...] = ()
+ for filter_spec in input_metric_filter_set.query_level_filter_specs:
+ included_agg_time_specs = (
+ filter_spec.linkable_spec_set.included_agg_time_dimension_specs_for_metric(
+ metric_reference=metric_spec.reference, metric_lookup=self._metric_lookup
+ )
)
+ if set(included_agg_time_specs) == set(filter_spec.linkable_spec_set.as_tuple):
+ query_level_agg_time_filter_specs += (filter_spec,)
+ else:
+ query_level_non_agg_time_filter_specs += (filter_spec,)
+ # Rewrite input metric spec with non-metric time filters
+ input_metric_spec = input_metric_spec.with_new_filter_spec_set(
+ input_metric_filter_set.replace_query_level_filter_specs(query_level_non_agg_time_filter_specs)
+ )
+
+ input_metric_parent_node = self._build_any_metric_output_node(
+ BuildAnyMetricOutputNodeParameterSet(
+ metric_spec=input_metric_spec,
+ queried_linkable_specs=queried_linkable_specs,
+ filter_spec_factory=filter_spec_factory,
+ predicate_pushdown_state=metric_pushdown_state,
+ time_spine_filter_specs=query_level_agg_time_filter_specs,
+ for_group_by_source_node=False,
)
)
+ parent_nodes.append(input_metric_parent_node)
parent_node = (
parent_nodes[0]
@@ -648,35 +641,17 @@ def _build_derived_metric_output_node(
queried_agg_time_dimension_specs = queried_linkable_specs.included_agg_time_dimension_specs_for_metric(
metric_reference=metric_spec.reference, metric_lookup=self._metric_lookup
)
- assert (
- queried_agg_time_dimension_specs
- ), "Joining to time spine requires querying with metric_time or the appropriate agg_time_dimension."
output_node = JoinToTimeSpineNode.create(
parent_node=output_node,
requested_agg_time_dimension_specs=queried_agg_time_dimension_specs,
use_custom_agg_time_dimension=not queried_linkable_specs.contains_metric_time,
time_range_constraint=predicate_pushdown_state.time_range_constraint,
+ time_spine_filters=time_spine_filter_specs,
offset_window=metric_spec.offset_window,
offset_to_grain=metric_spec.offset_to_grain,
join_type=SqlJoinType.INNER,
)
- if len(metric_spec.filter_spec_set.all_filter_specs) > 0:
- output_node = WhereConstraintNode.create(
- parent_node=output_node, where_specs=metric_spec.filter_spec_set.all_filter_specs
- )
- specs_in_filters = set(
- linkable_spec
- for filter_spec in metric_spec.filter_spec_set.all_filter_specs
- for linkable_spec in filter_spec.linkable_specs
- )
- if not specs_in_filters.issubset(queried_linkable_specs.as_tuple):
- output_node = FilterElementsNode.create(
- parent_node=output_node,
- include_specs=InstanceSpecSet(metric_specs=(metric_spec,)).merge(
- InstanceSpecSet.create_from_specs(queried_linkable_specs.as_tuple)
- ),
- )
return output_node
def _build_any_metric_output_node(self, parameter_set: BuildAnyMetricOutputNodeParameterSet) -> DataflowPlanNode:
@@ -698,6 +673,7 @@ def _build_any_metric_output_node_non_cached(
filter_spec_factory = parameter_set.filter_spec_factory
predicate_pushdown_state = parameter_set.predicate_pushdown_state
for_group_by_source_node = parameter_set.for_group_by_source_node
+ time_spine_filter_specs = parameter_set.time_spine_filter_specs
metric = self._metric_lookup.get_metric(metric_spec.reference)
@@ -708,6 +684,7 @@ def _build_any_metric_output_node_non_cached(
filter_spec_factory=filter_spec_factory,
predicate_pushdown_state=predicate_pushdown_state,
for_group_by_source_node=for_group_by_source_node,
+ time_spine_filter_specs=time_spine_filter_specs,
)
elif metric.type is MetricType.CUMULATIVE:
@@ -717,6 +694,7 @@ def _build_any_metric_output_node_non_cached(
filter_spec_factory=filter_spec_factory,
predicate_pushdown_state=predicate_pushdown_state,
for_group_by_source_node=for_group_by_source_node,
+ time_spine_filter_specs=time_spine_filter_specs,
)
elif metric.type is MetricType.RATIO or metric.type is MetricType.DERIVED:
@@ -726,6 +704,7 @@ def _build_any_metric_output_node_non_cached(
filter_spec_factory=filter_spec_factory,
predicate_pushdown_state=predicate_pushdown_state,
for_group_by_source_node=for_group_by_source_node,
+ time_spine_filter_specs=time_spine_filter_specs,
)
elif metric.type is MetricType.CONVERSION:
return self._build_conversion_metric_output_node(
@@ -734,6 +713,7 @@ def _build_any_metric_output_node_non_cached(
filter_spec_factory=filter_spec_factory,
predicate_pushdown_state=predicate_pushdown_state,
for_group_by_source_node=for_group_by_source_node,
+ time_spine_filter_specs=time_spine_filter_specs,
)
assert_values_exhausted(metric.type)
@@ -1383,42 +1363,54 @@ def _build_filter_specs_for_input_measure(
)
return filter_spec_set.merge(descendent_filter_spec_set)
- def _build_input_metric_specs_for_derived_metric(
+ def _build_input_metric_specs(
self,
- metric_reference: MetricReference,
+ metric_spec: MetricSpec,
filter_spec_factory: WhereSpecFactory,
) -> Sequence[MetricSpec]:
"""Return the metric specs referenced by the metric. Current use case is for derived metrics."""
- metric = self._metric_lookup.get_metric(metric_reference)
+ metric = self._metric_lookup.get_metric(metric_spec.reference)
input_metric_specs: List[MetricSpec] = []
+ # The metric spec already has the query-level filter specs. If the outer metric was also an input metric on another
+ # derived metric (in the case of a nested derived metric) any metric_level_filter_specs here were inherited from that
+ # input metric and should be treated as query-level filters here.
+ query_level_filter_specs = (
+ metric_spec.filter_spec_set.query_level_filter_specs + metric_spec.filter_spec_set.metric_level_filter_specs
+ )
+
+ # For the purpose of input metrics, outer metric filters should be treated as query-level filters.
+ outer_metric_filter_specs = filter_spec_factory.create_from_where_filter_intersection(
+ filter_location=WhereFilterLocation.for_metric(metric_reference=metric_spec.reference),
+ filter_intersection=metric.filter,
+ )
+ query_level_filter_specs += tuple(outer_metric_filter_specs)
+
for input_metric in metric.input_metrics:
+ input_metric_filter_specs = filter_spec_factory.create_from_where_filter_intersection(
+ filter_location=WhereFilterLocation.for_input_metric(input_metric_reference=input_metric.as_reference),
+ filter_intersection=input_metric.filter,
+ )
filter_spec_set = WhereFilterSpecSet(
- metric_level_filter_specs=tuple(
- filter_spec_factory.create_from_where_filter_intersection(
- filter_location=WhereFilterLocation.for_input_metric(
- input_metric_reference=input_metric.as_reference
- ),
- filter_intersection=input_metric.filter,
- )
- ),
+ metric_level_filter_specs=tuple(input_metric_filter_specs),
+ query_level_filter_specs=tuple(query_level_filter_specs),
)
- spec = MetricSpec(
+ offset_window = (
+ PydanticMetricTimeWindow(
+ count=input_metric.offset_window.count, granularity=input_metric.offset_window.granularity
+ )
+ if input_metric.offset_window
+ else None
+ )
+ input_metric_spec = MetricSpec(
element_name=input_metric.name,
filter_spec_set=filter_spec_set,
alias=input_metric.alias,
- offset_window=(
- PydanticMetricTimeWindow(
- count=input_metric.offset_window.count,
- granularity=input_metric.offset_window.granularity,
- )
- if input_metric.offset_window
- else None
- ),
+ offset_window=offset_window,
offset_to_grain=input_metric.offset_to_grain,
)
- input_metric_specs.append(spec)
+ input_metric_specs.append(input_metric_spec)
return tuple(input_metric_specs)
def build_aggregated_measure(
@@ -1426,6 +1418,7 @@ def build_aggregated_measure(
metric_input_measure_spec: MetricInputMeasureSpec,
queried_linkable_specs: LinkableSpecSet,
predicate_pushdown_state: PredicatePushdownState,
+ time_spine_filter_specs: Sequence[WhereFilterSpec],
measure_recipe: Optional[SourceNodeRecipe] = None,
) -> DataflowPlanNode:
"""Returns a node where the measures are aggregated by the linkable specs and constrained appropriately.
@@ -1449,6 +1442,7 @@ def build_aggregated_measure(
queried_linkable_specs=queried_linkable_specs,
predicate_pushdown_state=predicate_pushdown_state,
measure_recipe=measure_recipe,
+ time_spine_filter_specs=time_spine_filter_specs,
)
def __get_required_linkable_specs(
@@ -1497,6 +1491,7 @@ def _build_aggregated_measure_from_measure_source_node(
queried_linkable_specs: LinkableSpecSet,
predicate_pushdown_state: PredicatePushdownState,
measure_recipe: Optional[SourceNodeRecipe] = None,
+ time_spine_filter_specs: Sequence[WhereFilterSpec] = (),
) -> DataflowPlanNode:
measure_spec = metric_input_measure_spec.measure_spec
cumulative = metric_input_measure_spec.cumulative_description is not None
@@ -1631,6 +1626,7 @@ def _build_aggregated_measure_from_measure_source_node(
offset_window=before_aggregation_time_spine_join_description.offset_window,
offset_to_grain=before_aggregation_time_spine_join_description.offset_to_grain,
join_type=before_aggregation_time_spine_join_description.join_type,
+ time_spine_filters=time_spine_filter_specs,
)
custom_granularity_specs_to_join = [
@@ -1686,6 +1682,7 @@ def _build_aggregated_measure_from_measure_source_node(
if set(included_agg_time_specs) == set(filter_spec.linkable_spec_set.as_tuple):
agg_time_only_filters.append(filter_spec)
if filter_spec.linkable_spec_set.time_dimension_specs_with_custom_grain:
+ # TODO: dedupe this logic with where it's used elsewhere once this error is removed
raise ValueError(
"Using custom granularity in filters for `join_to_timespine` metrics is not yet fully supported. "
"This feature is coming soon!"
diff --git a/tests_metricflow/integration/query_output/test_offset_metrics.py b/tests_metricflow/integration/query_output/test_offset_metrics.py
index d51b3f76b..411dfe432 100644
--- a/tests_metricflow/integration/query_output/test_offset_metrics.py
+++ b/tests_metricflow/integration/query_output/test_offset_metrics.py
@@ -58,3 +58,61 @@ def test_offset_to_grain_with_multiple_granularities( # noqa: D103
snapshot_str=query_result.result_df.text_format(),
sql_engine=sql_client.sql_engine_type,
)
+
+
+@pytest.mark.sql_engine_snapshot
+def test_nested_offset_window_metric_with_tiered_filters( # noqa: D103
+ request: FixtureRequest,
+ mf_test_configuration: MetricFlowTestConfiguration,
+ sql_client: SqlClient,
+ it_helpers: IntegrationTestHelpers,
+) -> None:
+ query_result = it_helpers.mf_engine.query(
+ MetricFlowQueryRequest.create_with_random_request_id(
+ metric_names=("bookings_offset_twice_with_tiered_filters",),
+ group_by_names=("metric_time__day",),
+ where_constraints=(
+ "{{ TimeDimension('booking__ds', 'quarter') }} >= '2020-01-02'",
+ "{{ TimeDimension('listing__created_at', 'day') }} = '2020-01-01'",
+ ),
+ order_by_names=["metric_time__day"],
+ )
+ )
+ assert query_result.result_df is not None, "Unexpected empty result."
+
+ assert_str_snapshot_equal(
+ request=request,
+ mf_test_configuration=mf_test_configuration,
+ snapshot_id="query_output",
+ snapshot_str=query_result.result_df.text_format(),
+ sql_engine=sql_client.sql_engine_type,
+ )
+
+
+@pytest.mark.sql_engine_snapshot
+def test_nested_offset_to_grain_metric_with_tiered_filters( # noqa: D103
+ request: FixtureRequest,
+ mf_test_configuration: MetricFlowTestConfiguration,
+ sql_client: SqlClient,
+ it_helpers: IntegrationTestHelpers,
+) -> None:
+ query_result = it_helpers.mf_engine.query(
+ MetricFlowQueryRequest.create_with_random_request_id(
+ metric_names=("bookings_offset_to_grain_twice_with_tiered_filters",),
+ group_by_names=("metric_time__day",),
+ where_constraints=(
+ "{{ Entity('listing') }} IS NOT NULL",
+ "{{ TimeDimension('metric_time', 'quarter') }} >= '2020-01-01'",
+ ),
+ order_by_names=["metric_time__day"],
+ )
+ )
+ assert query_result.result_df is not None, "Unexpected empty result."
+
+ assert_str_snapshot_equal(
+ request=request,
+ mf_test_configuration=mf_test_configuration,
+ snapshot_id="query_output",
+ snapshot_str=query_result.result_df.text_format(),
+ sql_engine=sql_client.sql_engine_type,
+ )
diff --git a/tests_metricflow/integration/test_cases/itest_metrics.yaml b/tests_metricflow/integration/test_cases/itest_metrics.yaml
index d0d401161..885070ad0 100644
--- a/tests_metricflow/integration/test_cases/itest_metrics.yaml
+++ b/tests_metricflow/integration/test_cases/itest_metrics.yaml
@@ -1618,7 +1618,7 @@ integration_test:
model: SIMPLE_MODEL
metrics: ["bookings_offset_twice"]
group_by_objs: [{"name": "metric_time", "grain": "day"}]
- where_filter: "{{ render_time_constraint('metric_time__day', '2020-01-08', '2020-01-09') }}"
+ where_filter: "{{ render_time_dimension_template('metric_time__day') }} BETWEEN '2020-01-08' AND '2020-01-09'"
check_query: |
SELECT
subq_9.ds AS metric_time__day
diff --git a/tests_metricflow/query_rendering/test_derived_metric_rendering.py b/tests_metricflow/query_rendering/test_derived_metric_rendering.py
index b0985915f..690026e0e 100644
--- a/tests_metricflow/query_rendering/test_derived_metric_rendering.py
+++ b/tests_metricflow/query_rendering/test_derived_metric_rendering.py
@@ -821,3 +821,70 @@ def test_derived_metric_that_defines_the_same_alias_in_different_components(
dataflow_plan_builder=dataflow_plan_builder,
query_spec=query_spec,
)
+
+
+@pytest.mark.sql_engine_snapshot
+def test_nested_offset_window_metric_with_tiered_filters(
+ request: FixtureRequest,
+ mf_test_configuration: MetricFlowTestConfiguration,
+ dataflow_plan_builder: DataflowPlanBuilder,
+ query_parser: MetricFlowQueryParser,
+ sql_client: SqlClient,
+ dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
+) -> None:
+ """Tests that filters at different tiers are applied appropriately for derived metrics.
+
+ This includes filters at the input metric, metric, and query level. At each tier there are filters on both
+ metric_time / agg time and another dimension, which might have different behaviors.
+ """
+ # TODO: test with Trino, hard-coded filters might fail
+ query_spec = query_parser.parse_and_validate_query(
+ metric_names=("bookings_offset_twice_with_tiered_filters",),
+ group_by_names=("metric_time__day",),
+ where_constraints=[
+ # `booking_ds` is the agg_time_dimension
+ PydanticWhereFilter(where_sql_template=("{{ TimeDimension('booking__ds', 'quarter') }} >= '2020-01-01'")),
+ PydanticWhereFilter(
+ where_sql_template=("{{ TimeDimension('listing__created_at', 'day') }} = '2020-01-01'")
+ ),
+ ],
+ ).query_spec
+
+ render_and_check(
+ request=request,
+ mf_test_configuration=mf_test_configuration,
+ dataflow_to_sql_converter=dataflow_to_sql_converter,
+ sql_client=sql_client,
+ dataflow_plan_builder=dataflow_plan_builder,
+ query_spec=query_spec,
+ )
+
+
+@pytest.mark.sql_engine_snapshot
+def test_nested_offset_to_grain_metric_with_tiered_filters(
+ request: FixtureRequest,
+ mf_test_configuration: MetricFlowTestConfiguration,
+ dataflow_plan_builder: DataflowPlanBuilder,
+ query_parser: MetricFlowQueryParser,
+ sql_client: SqlClient,
+ dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
+) -> None:
+ """Tests that filters at different tiers are applied appropriately for derived metrics with offset to grain."""
+ # TODO: test with Trino, hard-coded filters might fail
+ query_spec = query_parser.parse_and_validate_query(
+ metric_names=("bookings_offset_to_grain_twice_with_tiered_filters",),
+ group_by_names=("metric_time__day",),
+ where_constraints=[
+ PydanticWhereFilter(where_sql_template=("{{ Entity('listing') }} IS NOT NULL")),
+ PydanticWhereFilter(where_sql_template=("{{ TimeDimension('metric_time', 'quarter') }} >= '2020-01-01'")),
+ ],
+ ).query_spec
+
+ render_and_check(
+ request=request,
+ mf_test_configuration=mf_test_configuration,
+ dataflow_to_sql_converter=dataflow_to_sql_converter,
+ sql_client=sql_client,
+ dataflow_plan_builder=dataflow_plan_builder,
+ query_spec=query_spec,
+ )
diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql
index 4c9d86d58..9a9e9938c 100644
--- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql
+++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0.sql
@@ -4,440 +4,337 @@ sql_engine: DuckDB
---
-- Compute Metrics via Expressions
SELECT
- subq_9.metric_time__day
+ subq_8.metric_time__day
, bookings_5_days_ago AS bookings_5_day_lag
FROM (
-- Compute Metrics via Expressions
SELECT
- subq_8.metric_time__day
- , subq_8.bookings AS bookings_5_days_ago
+ subq_7.metric_time__day
+ , subq_7.bookings AS bookings_5_days_ago
FROM (
-- Aggregate Measures
SELECT
- subq_7.metric_time__day
- , SUM(subq_7.bookings) AS bookings
+ subq_6.metric_time__day
+ , SUM(subq_6.bookings) AS bookings
FROM (
-- Pass Only Elements: ['bookings', 'metric_time__day']
SELECT
- subq_6.metric_time__day
- , subq_6.bookings
+ subq_5.metric_time__day
+ , subq_5.bookings
FROM (
- -- Constrain Output with WHERE
+ -- Join to Time Spine Dataset
SELECT
- subq_5.metric_time__martian_day
- , subq_5.metric_time__day
- , subq_5.metric_time__week
- , subq_5.metric_time__month
- , subq_5.metric_time__quarter
- , subq_5.metric_time__year
- , subq_5.metric_time__extract_year
- , subq_5.metric_time__extract_quarter
- , subq_5.metric_time__extract_month
- , subq_5.metric_time__extract_day
- , subq_5.metric_time__extract_dow
- , subq_5.metric_time__extract_doy
- , subq_5.ds__day
- , subq_5.ds__week
- , subq_5.ds__month
- , subq_5.ds__quarter
- , subq_5.ds__year
- , subq_5.ds__extract_year
- , subq_5.ds__extract_quarter
- , subq_5.ds__extract_month
- , subq_5.ds__extract_day
- , subq_5.ds__extract_dow
- , subq_5.ds__extract_doy
- , subq_5.ds_partitioned__day
- , subq_5.ds_partitioned__week
- , subq_5.ds_partitioned__month
- , subq_5.ds_partitioned__quarter
- , subq_5.ds_partitioned__year
- , subq_5.ds_partitioned__extract_year
- , subq_5.ds_partitioned__extract_quarter
- , subq_5.ds_partitioned__extract_month
- , subq_5.ds_partitioned__extract_day
- , subq_5.ds_partitioned__extract_dow
- , subq_5.ds_partitioned__extract_doy
- , subq_5.paid_at__day
- , subq_5.paid_at__week
- , subq_5.paid_at__month
- , subq_5.paid_at__quarter
- , subq_5.paid_at__year
- , subq_5.paid_at__extract_year
- , subq_5.paid_at__extract_quarter
- , subq_5.paid_at__extract_month
- , subq_5.paid_at__extract_day
- , subq_5.paid_at__extract_dow
- , subq_5.paid_at__extract_doy
- , subq_5.booking__ds__day
- , subq_5.booking__ds__week
- , subq_5.booking__ds__month
- , subq_5.booking__ds__quarter
- , subq_5.booking__ds__year
- , subq_5.booking__ds__extract_year
- , subq_5.booking__ds__extract_quarter
- , subq_5.booking__ds__extract_month
- , subq_5.booking__ds__extract_day
- , subq_5.booking__ds__extract_dow
- , subq_5.booking__ds__extract_doy
- , subq_5.booking__ds_partitioned__day
- , subq_5.booking__ds_partitioned__week
- , subq_5.booking__ds_partitioned__month
- , subq_5.booking__ds_partitioned__quarter
- , subq_5.booking__ds_partitioned__year
- , subq_5.booking__ds_partitioned__extract_year
- , subq_5.booking__ds_partitioned__extract_quarter
- , subq_5.booking__ds_partitioned__extract_month
- , subq_5.booking__ds_partitioned__extract_day
- , subq_5.booking__ds_partitioned__extract_dow
- , subq_5.booking__ds_partitioned__extract_doy
- , subq_5.booking__paid_at__day
- , subq_5.booking__paid_at__week
- , subq_5.booking__paid_at__month
- , subq_5.booking__paid_at__quarter
- , subq_5.booking__paid_at__year
- , subq_5.booking__paid_at__extract_year
- , subq_5.booking__paid_at__extract_quarter
- , subq_5.booking__paid_at__extract_month
- , subq_5.booking__paid_at__extract_day
- , subq_5.booking__paid_at__extract_dow
- , subq_5.booking__paid_at__extract_doy
- , subq_5.listing
- , subq_5.guest
- , subq_5.host
- , subq_5.booking__listing
- , subq_5.booking__guest
- , subq_5.booking__host
- , subq_5.is_instant
- , subq_5.booking__is_instant
- , subq_5.bookings
- , subq_5.instant_bookings
- , subq_5.booking_value
- , subq_5.max_booking_value
- , subq_5.min_booking_value
- , subq_5.bookers
- , subq_5.average_booking_value
- , subq_5.referred_bookings
- , subq_5.median_booking_value
- , subq_5.booking_value_p99
- , subq_5.discrete_booking_value_p99
- , subq_5.approximate_continuous_booking_value_p99
- , subq_5.approximate_discrete_booking_value_p99
+ subq_2.metric_time__day AS metric_time__day
+ , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week
+ , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month
+ , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter
+ , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year
+ , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year
+ , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter
+ , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month
+ , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day
+ , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow
+ , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy
+ , subq_1.ds__day AS ds__day
+ , subq_1.ds__week AS ds__week
+ , subq_1.ds__month AS ds__month
+ , subq_1.ds__quarter AS ds__quarter
+ , subq_1.ds__year AS ds__year
+ , subq_1.ds__extract_year AS ds__extract_year
+ , subq_1.ds__extract_quarter AS ds__extract_quarter
+ , subq_1.ds__extract_month AS ds__extract_month
+ , subq_1.ds__extract_day AS ds__extract_day
+ , subq_1.ds__extract_dow AS ds__extract_dow
+ , subq_1.ds__extract_doy AS ds__extract_doy
+ , subq_1.ds_partitioned__day AS ds_partitioned__day
+ , subq_1.ds_partitioned__week AS ds_partitioned__week
+ , subq_1.ds_partitioned__month AS ds_partitioned__month
+ , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_1.ds_partitioned__year AS ds_partitioned__year
+ , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_1.paid_at__day AS paid_at__day
+ , subq_1.paid_at__week AS paid_at__week
+ , subq_1.paid_at__month AS paid_at__month
+ , subq_1.paid_at__quarter AS paid_at__quarter
+ , subq_1.paid_at__year AS paid_at__year
+ , subq_1.paid_at__extract_year AS paid_at__extract_year
+ , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_1.paid_at__extract_month AS paid_at__extract_month
+ , subq_1.paid_at__extract_day AS paid_at__extract_day
+ , subq_1.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_1.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_1.booking__ds__day AS booking__ds__day
+ , subq_1.booking__ds__week AS booking__ds__week
+ , subq_1.booking__ds__month AS booking__ds__month
+ , subq_1.booking__ds__quarter AS booking__ds__quarter
+ , subq_1.booking__ds__year AS booking__ds__year
+ , subq_1.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_1.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_1.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_1.booking__paid_at__day AS booking__paid_at__day
+ , subq_1.booking__paid_at__week AS booking__paid_at__week
+ , subq_1.booking__paid_at__month AS booking__paid_at__month
+ , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_1.booking__paid_at__year AS booking__paid_at__year
+ , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_1.listing AS listing
+ , subq_1.guest AS guest
+ , subq_1.host AS host
+ , subq_1.booking__listing AS booking__listing
+ , subq_1.booking__guest AS booking__guest
+ , subq_1.booking__host AS booking__host
+ , subq_1.is_instant AS is_instant
+ , subq_1.booking__is_instant AS booking__is_instant
+ , subq_1.bookings AS bookings
+ , subq_1.instant_bookings AS instant_bookings
+ , subq_1.booking_value AS booking_value
+ , subq_1.max_booking_value AS max_booking_value
+ , subq_1.min_booking_value AS min_booking_value
+ , subq_1.bookers AS bookers
+ , subq_1.average_booking_value AS average_booking_value
+ , subq_1.referred_bookings AS referred_bookings
+ , subq_1.median_booking_value AS median_booking_value
+ , subq_1.booking_value_p99 AS booking_value_p99
+ , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
FROM (
- -- Join to Time Spine Dataset
- -- Join to Custom Granularity Dataset
+ -- Filter Time Spine
SELECT
- subq_2.metric_time__day AS metric_time__day
- , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week
- , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month
- , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter
- , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year
- , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year
- , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter
- , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month
- , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day
- , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow
- , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy
- , subq_1.ds__day AS ds__day
- , subq_1.ds__week AS ds__week
- , subq_1.ds__month AS ds__month
- , subq_1.ds__quarter AS ds__quarter
- , subq_1.ds__year AS ds__year
- , subq_1.ds__extract_year AS ds__extract_year
- , subq_1.ds__extract_quarter AS ds__extract_quarter
- , subq_1.ds__extract_month AS ds__extract_month
- , subq_1.ds__extract_day AS ds__extract_day
- , subq_1.ds__extract_dow AS ds__extract_dow
- , subq_1.ds__extract_doy AS ds__extract_doy
- , subq_1.ds_partitioned__day AS ds_partitioned__day
- , subq_1.ds_partitioned__week AS ds_partitioned__week
- , subq_1.ds_partitioned__month AS ds_partitioned__month
- , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter
- , subq_1.ds_partitioned__year AS ds_partitioned__year
- , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year
- , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
- , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month
- , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day
- , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
- , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
- , subq_1.paid_at__day AS paid_at__day
- , subq_1.paid_at__week AS paid_at__week
- , subq_1.paid_at__month AS paid_at__month
- , subq_1.paid_at__quarter AS paid_at__quarter
- , subq_1.paid_at__year AS paid_at__year
- , subq_1.paid_at__extract_year AS paid_at__extract_year
- , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter
- , subq_1.paid_at__extract_month AS paid_at__extract_month
- , subq_1.paid_at__extract_day AS paid_at__extract_day
- , subq_1.paid_at__extract_dow AS paid_at__extract_dow
- , subq_1.paid_at__extract_doy AS paid_at__extract_doy
- , subq_1.booking__ds__day AS booking__ds__day
- , subq_1.booking__ds__week AS booking__ds__week
- , subq_1.booking__ds__month AS booking__ds__month
- , subq_1.booking__ds__quarter AS booking__ds__quarter
- , subq_1.booking__ds__year AS booking__ds__year
- , subq_1.booking__ds__extract_year AS booking__ds__extract_year
- , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter
- , subq_1.booking__ds__extract_month AS booking__ds__extract_month
- , subq_1.booking__ds__extract_day AS booking__ds__extract_day
- , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow
- , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy
- , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day
- , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week
- , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month
- , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
- , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year
- , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
- , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
- , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
- , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
- , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
- , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
- , subq_1.booking__paid_at__day AS booking__paid_at__day
- , subq_1.booking__paid_at__week AS booking__paid_at__week
- , subq_1.booking__paid_at__month AS booking__paid_at__month
- , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter
- , subq_1.booking__paid_at__year AS booking__paid_at__year
- , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year
- , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
- , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month
- , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day
- , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
- , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
- , subq_1.listing AS listing
- , subq_1.guest AS guest
- , subq_1.host AS host
- , subq_1.booking__listing AS booking__listing
- , subq_1.booking__guest AS booking__guest
- , subq_1.booking__host AS booking__host
- , subq_1.is_instant AS is_instant
- , subq_1.booking__is_instant AS booking__is_instant
- , subq_1.bookings AS bookings
- , subq_1.instant_bookings AS instant_bookings
- , subq_1.booking_value AS booking_value
- , subq_1.max_booking_value AS max_booking_value
- , subq_1.min_booking_value AS min_booking_value
- , subq_1.bookers AS bookers
- , subq_1.average_booking_value AS average_booking_value
- , subq_1.referred_bookings AS referred_bookings
- , subq_1.median_booking_value AS median_booking_value
- , subq_1.booking_value_p99 AS booking_value_p99
- , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99
- , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
- , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
- , subq_4.martian_day AS metric_time__martian_day
+ subq_4.metric_time__day
FROM (
-- Time Spine
SELECT
- subq_3.ds AS metric_time__day
+ subq_3.martian_day AS metric_time__martian_day
+ , subq_3.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_3
- ) subq_2
- INNER JOIN (
- -- Metric Time Dimension 'ds'
+ ) subq_4
+ WHERE metric_time__martian_day = '2020-01-01'
+ ) subq_2
+ INNER JOIN (
+ -- 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
- 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
- ON
- subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day
- LEFT OUTER JOIN
- ***************************.mf_time_spine subq_4
- ON
- subq_2.metric_time__day = subq_4.ds
- ) subq_5
- WHERE metric_time__martian_day = '2020-01-01'
- ) subq_6
- ) subq_7
+ 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
+ ON
+ subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day
+ ) subq_5
+ ) subq_6
GROUP BY
- subq_7.metric_time__day
- ) subq_8
-) subq_9
+ subq_6.metric_time__day
+ ) subq_7
+) subq_8
diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql
index a74e4042e..2f015fd1d 100644
--- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_offset_metric_with_custom_granularity_filter_not_in_group_by__plan0_optimized.sql
@@ -7,37 +7,36 @@ SELECT
metric_time__day
, bookings_5_days_ago AS bookings_5_day_lag
FROM (
- -- Constrain Output with WHERE
+ -- Join to Time Spine Dataset
-- Pass Only Elements: ['bookings', 'metric_time__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
- metric_time__day
- , SUM(bookings) AS bookings_5_days_ago
+ subq_11.metric_time__day AS metric_time__day
+ , SUM(subq_10.bookings) AS bookings_5_days_ago
FROM (
- -- Join to Time Spine Dataset
- -- Join to Custom Granularity Dataset
+ -- Filter Time Spine
SELECT
- subq_13.ds AS metric_time__day
- , subq_11.bookings AS bookings
- , subq_14.martian_day AS metric_time__martian_day
- FROM ***************************.mf_time_spine subq_13
- INNER JOIN (
- -- Read Elements From Semantic Model 'bookings_source'
- -- Metric Time Dimension 'ds'
+ metric_time__day
+ FROM (
+ -- Time Spine
SELECT
- DATE_TRUNC('day', ds) AS metric_time__day
- , 1 AS bookings
- FROM ***************************.fct_bookings bookings_source_src_28000
- ) subq_11
- ON
- subq_13.ds - INTERVAL 5 day = subq_11.metric_time__day
- LEFT OUTER JOIN
- ***************************.mf_time_spine subq_14
- ON
- subq_13.ds = subq_14.ds
- ) subq_15
- WHERE metric_time__martian_day = '2020-01-01'
+ martian_day AS metric_time__martian_day
+ , ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_12
+ ) subq_13
+ WHERE metric_time__martian_day = '2020-01-01'
+ ) subq_11
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_28000
+ ) subq_10
+ ON
+ subq_11.metric_time__day - INTERVAL 5 day = subq_10.metric_time__day
GROUP BY
- metric_time__day
-) subq_19
+ subq_11.metric_time__day
+) subq_17
diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml
index 69377fe72..75b5fa110 100644
--- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml
+++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml
@@ -59,54 +59,13 @@ docstring:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
@@ -120,71 +79,31 @@ docstring:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml
index 37a544add..fa0296218 100644
--- a/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml
+++ b/tests_metricflow/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml
@@ -62,53 +62,12 @@ docstring:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -122,74 +81,31 @@ docstring:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -257,7 +173,7 @@ docstring:
-
+
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql
index e18ced63c..4b1e04d4b 100644
--- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql
@@ -346,412 +346,315 @@ FROM (
subq_11.metric_time__day
, subq_11.bookings
FROM (
- -- Constrain Output with WHERE
+ -- Join to Time Spine Dataset
SELECT
- subq_10.metric_time__day
- , subq_10.metric_time__week
- , subq_10.metric_time__month
- , subq_10.metric_time__quarter
- , subq_10.metric_time__year
- , subq_10.metric_time__extract_year
- , subq_10.metric_time__extract_quarter
- , subq_10.metric_time__extract_month
- , subq_10.metric_time__extract_day
- , subq_10.metric_time__extract_dow
- , subq_10.metric_time__extract_doy
- , subq_10.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.listing
- , subq_10.guest
- , subq_10.host
- , subq_10.booking__listing
- , subq_10.booking__guest
- , subq_10.booking__host
- , subq_10.is_instant
- , subq_10.booking__is_instant
- , subq_10.bookings
- , subq_10.instant_bookings
- , subq_10.booking_value
- , subq_10.max_booking_value
- , subq_10.min_booking_value
- , subq_10.bookers
- , subq_10.average_booking_value
- , subq_10.referred_bookings
- , subq_10.median_booking_value
- , subq_10.booking_value_p99
- , subq_10.discrete_booking_value_p99
- , subq_10.approximate_continuous_booking_value_p99
- , subq_10.approximate_discrete_booking_value_p99
+ subq_8.metric_time__day AS metric_time__day
+ , DATE_TRUNC('week', subq_8.metric_time__day) AS metric_time__week
+ , DATE_TRUNC('month', subq_8.metric_time__day) AS metric_time__month
+ , DATE_TRUNC('quarter', subq_8.metric_time__day) AS metric_time__quarter
+ , DATE_TRUNC('year', subq_8.metric_time__day) AS metric_time__year
+ , EXTRACT(year FROM subq_8.metric_time__day) AS metric_time__extract_year
+ , EXTRACT(quarter FROM subq_8.metric_time__day) AS metric_time__extract_quarter
+ , EXTRACT(month FROM subq_8.metric_time__day) AS metric_time__extract_month
+ , EXTRACT(day FROM subq_8.metric_time__day) AS metric_time__extract_day
+ , EXTRACT(isodow FROM subq_8.metric_time__day) AS metric_time__extract_dow
+ , EXTRACT(doy FROM subq_8.metric_time__day) AS metric_time__extract_doy
+ , subq_7.ds__day AS ds__day
+ , subq_7.ds__week AS ds__week
+ , subq_7.ds__month AS ds__month
+ , subq_7.ds__quarter AS ds__quarter
+ , subq_7.ds__year AS ds__year
+ , subq_7.ds__extract_year AS ds__extract_year
+ , subq_7.ds__extract_quarter AS ds__extract_quarter
+ , subq_7.ds__extract_month AS ds__extract_month
+ , subq_7.ds__extract_day AS ds__extract_day
+ , subq_7.ds__extract_dow AS ds__extract_dow
+ , subq_7.ds__extract_doy AS ds__extract_doy
+ , subq_7.ds_partitioned__day AS ds_partitioned__day
+ , subq_7.ds_partitioned__week AS ds_partitioned__week
+ , subq_7.ds_partitioned__month AS ds_partitioned__month
+ , subq_7.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_7.ds_partitioned__year AS ds_partitioned__year
+ , subq_7.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_7.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_7.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_7.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_7.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_7.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_7.paid_at__day AS paid_at__day
+ , subq_7.paid_at__week AS paid_at__week
+ , subq_7.paid_at__month AS paid_at__month
+ , subq_7.paid_at__quarter AS paid_at__quarter
+ , subq_7.paid_at__year AS paid_at__year
+ , subq_7.paid_at__extract_year AS paid_at__extract_year
+ , subq_7.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_7.paid_at__extract_month AS paid_at__extract_month
+ , subq_7.paid_at__extract_day AS paid_at__extract_day
+ , subq_7.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_7.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_7.booking__ds__day AS booking__ds__day
+ , subq_7.booking__ds__week AS booking__ds__week
+ , subq_7.booking__ds__month AS booking__ds__month
+ , subq_7.booking__ds__quarter AS booking__ds__quarter
+ , subq_7.booking__ds__year AS booking__ds__year
+ , subq_7.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_7.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_7.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_7.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_7.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_7.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_7.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_7.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_7.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_7.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_7.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_7.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_7.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_7.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_7.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_7.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_7.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_7.booking__paid_at__day AS booking__paid_at__day
+ , subq_7.booking__paid_at__week AS booking__paid_at__week
+ , subq_7.booking__paid_at__month AS booking__paid_at__month
+ , subq_7.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_7.booking__paid_at__year AS booking__paid_at__year
+ , subq_7.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_7.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_7.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_7.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_7.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_7.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_7.listing AS listing
+ , subq_7.guest AS guest
+ , subq_7.host AS host
+ , subq_7.booking__listing AS booking__listing
+ , subq_7.booking__guest AS booking__guest
+ , subq_7.booking__host AS booking__host
+ , subq_7.is_instant AS is_instant
+ , subq_7.booking__is_instant AS booking__is_instant
+ , subq_7.bookings AS bookings
+ , subq_7.instant_bookings AS instant_bookings
+ , subq_7.booking_value AS booking_value
+ , subq_7.max_booking_value AS max_booking_value
+ , subq_7.min_booking_value AS min_booking_value
+ , subq_7.bookers AS bookers
+ , subq_7.average_booking_value AS average_booking_value
+ , subq_7.referred_bookings AS referred_bookings
+ , subq_7.median_booking_value AS median_booking_value
+ , subq_7.booking_value_p99 AS booking_value_p99
+ , subq_7.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_7.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_7.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
FROM (
- -- Join to Time Spine Dataset
+ -- Filter Time Spine
SELECT
- subq_8.metric_time__day AS metric_time__day
- , DATE_TRUNC('week', subq_8.metric_time__day) AS metric_time__week
- , DATE_TRUNC('month', subq_8.metric_time__day) AS metric_time__month
- , DATE_TRUNC('quarter', subq_8.metric_time__day) AS metric_time__quarter
- , DATE_TRUNC('year', subq_8.metric_time__day) AS metric_time__year
- , EXTRACT(year FROM subq_8.metric_time__day) AS metric_time__extract_year
- , EXTRACT(quarter FROM subq_8.metric_time__day) AS metric_time__extract_quarter
- , EXTRACT(month FROM subq_8.metric_time__day) AS metric_time__extract_month
- , EXTRACT(day FROM subq_8.metric_time__day) AS metric_time__extract_day
- , EXTRACT(isodow FROM subq_8.metric_time__day) AS metric_time__extract_dow
- , EXTRACT(doy FROM subq_8.metric_time__day) AS metric_time__extract_doy
- , subq_7.ds__day AS ds__day
- , subq_7.ds__week AS ds__week
- , subq_7.ds__month AS ds__month
- , subq_7.ds__quarter AS ds__quarter
- , subq_7.ds__year AS ds__year
- , subq_7.ds__extract_year AS ds__extract_year
- , subq_7.ds__extract_quarter AS ds__extract_quarter
- , subq_7.ds__extract_month AS ds__extract_month
- , subq_7.ds__extract_day AS ds__extract_day
- , subq_7.ds__extract_dow AS ds__extract_dow
- , subq_7.ds__extract_doy AS ds__extract_doy
- , subq_7.ds_partitioned__day AS ds_partitioned__day
- , subq_7.ds_partitioned__week AS ds_partitioned__week
- , subq_7.ds_partitioned__month AS ds_partitioned__month
- , subq_7.ds_partitioned__quarter AS ds_partitioned__quarter
- , subq_7.ds_partitioned__year AS ds_partitioned__year
- , subq_7.ds_partitioned__extract_year AS ds_partitioned__extract_year
- , subq_7.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
- , subq_7.ds_partitioned__extract_month AS ds_partitioned__extract_month
- , subq_7.ds_partitioned__extract_day AS ds_partitioned__extract_day
- , subq_7.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
- , subq_7.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
- , subq_7.paid_at__day AS paid_at__day
- , subq_7.paid_at__week AS paid_at__week
- , subq_7.paid_at__month AS paid_at__month
- , subq_7.paid_at__quarter AS paid_at__quarter
- , subq_7.paid_at__year AS paid_at__year
- , subq_7.paid_at__extract_year AS paid_at__extract_year
- , subq_7.paid_at__extract_quarter AS paid_at__extract_quarter
- , subq_7.paid_at__extract_month AS paid_at__extract_month
- , subq_7.paid_at__extract_day AS paid_at__extract_day
- , subq_7.paid_at__extract_dow AS paid_at__extract_dow
- , subq_7.paid_at__extract_doy AS paid_at__extract_doy
- , subq_7.booking__ds__day AS booking__ds__day
- , subq_7.booking__ds__week AS booking__ds__week
- , subq_7.booking__ds__month AS booking__ds__month
- , subq_7.booking__ds__quarter AS booking__ds__quarter
- , subq_7.booking__ds__year AS booking__ds__year
- , subq_7.booking__ds__extract_year AS booking__ds__extract_year
- , subq_7.booking__ds__extract_quarter AS booking__ds__extract_quarter
- , subq_7.booking__ds__extract_month AS booking__ds__extract_month
- , subq_7.booking__ds__extract_day AS booking__ds__extract_day
- , subq_7.booking__ds__extract_dow AS booking__ds__extract_dow
- , subq_7.booking__ds__extract_doy AS booking__ds__extract_doy
- , subq_7.booking__ds_partitioned__day AS booking__ds_partitioned__day
- , subq_7.booking__ds_partitioned__week AS booking__ds_partitioned__week
- , subq_7.booking__ds_partitioned__month AS booking__ds_partitioned__month
- , subq_7.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
- , subq_7.booking__ds_partitioned__year AS booking__ds_partitioned__year
- , subq_7.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
- , subq_7.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
- , subq_7.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
- , subq_7.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
- , subq_7.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
- , subq_7.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
- , subq_7.booking__paid_at__day AS booking__paid_at__day
- , subq_7.booking__paid_at__week AS booking__paid_at__week
- , subq_7.booking__paid_at__month AS booking__paid_at__month
- , subq_7.booking__paid_at__quarter AS booking__paid_at__quarter
- , subq_7.booking__paid_at__year AS booking__paid_at__year
- , subq_7.booking__paid_at__extract_year AS booking__paid_at__extract_year
- , subq_7.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
- , subq_7.booking__paid_at__extract_month AS booking__paid_at__extract_month
- , subq_7.booking__paid_at__extract_day AS booking__paid_at__extract_day
- , subq_7.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
- , subq_7.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
- , subq_7.listing AS listing
- , subq_7.guest AS guest
- , subq_7.host AS host
- , subq_7.booking__listing AS booking__listing
- , subq_7.booking__guest AS booking__guest
- , subq_7.booking__host AS booking__host
- , subq_7.is_instant AS is_instant
- , subq_7.booking__is_instant AS booking__is_instant
- , subq_7.bookings AS bookings
- , subq_7.instant_bookings AS instant_bookings
- , subq_7.booking_value AS booking_value
- , subq_7.max_booking_value AS max_booking_value
- , subq_7.min_booking_value AS min_booking_value
- , subq_7.bookers AS bookers
- , subq_7.average_booking_value AS average_booking_value
- , subq_7.referred_bookings AS referred_bookings
- , subq_7.median_booking_value AS median_booking_value
- , subq_7.booking_value_p99 AS booking_value_p99
- , subq_7.discrete_booking_value_p99 AS discrete_booking_value_p99
- , subq_7.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
- , subq_7.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ subq_10.metric_time__day
FROM (
-- Time Spine
SELECT
subq_9.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_9
- ) subq_8
- INNER JOIN (
- -- Metric Time Dimension 'ds'
+ ) subq_10
+ WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14'
+ ) subq_8
+ INNER JOIN (
+ -- 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
- 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
- ON
- subq_8.metric_time__day - INTERVAL 14 day = subq_7.metric_time__day
- ) subq_10
- WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14'
+ 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
+ ON
+ subq_8.metric_time__day - INTERVAL 14 day = subq_7.metric_time__day
) subq_11
) subq_12
GROUP BY
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql
index 66f5fe7c5..8fa4255ce 100644
--- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql
@@ -33,33 +33,37 @@ FROM (
metric_time__day
) subq_21
FULL OUTER JOIN (
- -- Constrain Output with WHERE
+ -- Join to Time Spine Dataset
-- Pass Only Elements: ['bookings', 'metric_time__day']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
- metric_time__day
- , SUM(bookings) AS bookings_2_weeks_ago
+ subq_24.metric_time__day AS metric_time__day
+ , SUM(subq_23.bookings) AS bookings_2_weeks_ago
FROM (
- -- Join to Time Spine Dataset
+ -- Filter Time Spine
SELECT
- subq_25.ds AS metric_time__day
- , subq_23.bookings AS bookings
- FROM ***************************.mf_time_spine subq_25
- INNER JOIN (
- -- Read Elements From Semantic Model 'bookings_source'
- -- Metric Time Dimension 'ds'
+ metric_time__day
+ FROM (
+ -- Time Spine
SELECT
- DATE_TRUNC('day', ds) AS metric_time__day
- , 1 AS bookings
- FROM ***************************.fct_bookings bookings_source_src_28000
- ) subq_23
- ON
- subq_25.ds - INTERVAL 14 day = subq_23.metric_time__day
- ) subq_26
- WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14'
+ ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_25
+ ) subq_26
+ WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14'
+ ) subq_24
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_28000
+ ) subq_23
+ ON
+ subq_24.metric_time__day - INTERVAL 14 day = subq_23.metric_time__day
GROUP BY
- metric_time__day
+ subq_24.metric_time__day
) subq_30
ON
subq_21.metric_time__day = subq_30.metric_time__day
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql
index a2c06603c..b31833037 100644
--- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql
@@ -4,370 +4,453 @@ sql_engine: DuckDB
---
-- Compute Metrics via Expressions
SELECT
- subq_13.metric_time__day
+ subq_12.metric_time__day
, 2 * bookings_offset_once AS bookings_offset_twice
FROM (
- -- Pass Only Elements: ['metric_time__day', 'bookings_offset_once']
+ -- Join to Time Spine Dataset
SELECT
- subq_12.metric_time__day
- , subq_12.bookings_offset_once
+ subq_10.metric_time__day AS metric_time__day
+ , subq_9.bookings_offset_once AS bookings_offset_once
FROM (
- -- Constrain Output with WHERE
+ -- Time Spine
SELECT
- subq_11.metric_time__day
- , subq_11.booking__is_instant
- , subq_11.bookings_offset_once
+ subq_11.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_11
+ ) subq_10
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_8.metric_time__day
+ , 2 * bookings AS bookings_offset_once
FROM (
- -- Join to Time Spine Dataset
+ -- Compute Metrics via Expressions
SELECT
- subq_9.metric_time__day AS metric_time__day
- , subq_8.booking__is_instant AS booking__is_instant
- , subq_8.bookings_offset_once AS bookings_offset_once
+ subq_7.metric_time__day
+ , subq_7.bookings
FROM (
- -- Time Spine
- SELECT
- subq_10.ds AS metric_time__day
- FROM ***************************.mf_time_spine subq_10
- ) subq_9
- INNER JOIN (
- -- Compute Metrics via Expressions
+ -- Aggregate Measures
SELECT
- subq_7.metric_time__day
- , subq_7.booking__is_instant
- , 2 * bookings AS bookings_offset_once
+ subq_6.metric_time__day
+ , SUM(subq_6.bookings) AS bookings
FROM (
- -- Compute Metrics via Expressions
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
SELECT
- subq_6.metric_time__day
- , subq_6.booking__is_instant
- , subq_6.bookings
+ subq_5.metric_time__day
+ , subq_5.bookings
FROM (
- -- Aggregate Measures
+ -- Constrain Output with WHERE
SELECT
- subq_5.metric_time__day
- , subq_5.booking__is_instant
- , SUM(subq_5.bookings) AS bookings
+ subq_4.metric_time__day
+ , subq_4.metric_time__week
+ , subq_4.metric_time__month
+ , subq_4.metric_time__quarter
+ , subq_4.metric_time__year
+ , subq_4.metric_time__extract_year
+ , subq_4.metric_time__extract_quarter
+ , subq_4.metric_time__extract_month
+ , subq_4.metric_time__extract_day
+ , subq_4.metric_time__extract_dow
+ , subq_4.metric_time__extract_doy
+ , subq_4.ds__day
+ , subq_4.ds__week
+ , subq_4.ds__month
+ , subq_4.ds__quarter
+ , subq_4.ds__year
+ , subq_4.ds__extract_year
+ , subq_4.ds__extract_quarter
+ , subq_4.ds__extract_month
+ , subq_4.ds__extract_day
+ , subq_4.ds__extract_dow
+ , subq_4.ds__extract_doy
+ , subq_4.ds_partitioned__day
+ , subq_4.ds_partitioned__week
+ , subq_4.ds_partitioned__month
+ , subq_4.ds_partitioned__quarter
+ , subq_4.ds_partitioned__year
+ , subq_4.ds_partitioned__extract_year
+ , subq_4.ds_partitioned__extract_quarter
+ , subq_4.ds_partitioned__extract_month
+ , subq_4.ds_partitioned__extract_day
+ , subq_4.ds_partitioned__extract_dow
+ , subq_4.ds_partitioned__extract_doy
+ , subq_4.paid_at__day
+ , subq_4.paid_at__week
+ , subq_4.paid_at__month
+ , subq_4.paid_at__quarter
+ , subq_4.paid_at__year
+ , subq_4.paid_at__extract_year
+ , subq_4.paid_at__extract_quarter
+ , subq_4.paid_at__extract_month
+ , subq_4.paid_at__extract_day
+ , subq_4.paid_at__extract_dow
+ , subq_4.paid_at__extract_doy
+ , subq_4.booking__ds__day
+ , subq_4.booking__ds__week
+ , subq_4.booking__ds__month
+ , subq_4.booking__ds__quarter
+ , subq_4.booking__ds__year
+ , subq_4.booking__ds__extract_year
+ , subq_4.booking__ds__extract_quarter
+ , subq_4.booking__ds__extract_month
+ , subq_4.booking__ds__extract_day
+ , subq_4.booking__ds__extract_dow
+ , subq_4.booking__ds__extract_doy
+ , subq_4.booking__ds_partitioned__day
+ , subq_4.booking__ds_partitioned__week
+ , subq_4.booking__ds_partitioned__month
+ , subq_4.booking__ds_partitioned__quarter
+ , subq_4.booking__ds_partitioned__year
+ , subq_4.booking__ds_partitioned__extract_year
+ , subq_4.booking__ds_partitioned__extract_quarter
+ , subq_4.booking__ds_partitioned__extract_month
+ , subq_4.booking__ds_partitioned__extract_day
+ , subq_4.booking__ds_partitioned__extract_dow
+ , subq_4.booking__ds_partitioned__extract_doy
+ , subq_4.booking__paid_at__day
+ , subq_4.booking__paid_at__week
+ , subq_4.booking__paid_at__month
+ , subq_4.booking__paid_at__quarter
+ , subq_4.booking__paid_at__year
+ , subq_4.booking__paid_at__extract_year
+ , subq_4.booking__paid_at__extract_quarter
+ , subq_4.booking__paid_at__extract_month
+ , subq_4.booking__paid_at__extract_day
+ , subq_4.booking__paid_at__extract_dow
+ , subq_4.booking__paid_at__extract_doy
+ , subq_4.listing
+ , subq_4.guest
+ , subq_4.host
+ , subq_4.booking__listing
+ , subq_4.booking__guest
+ , subq_4.booking__host
+ , subq_4.is_instant
+ , subq_4.booking__is_instant
+ , subq_4.bookings
+ , subq_4.instant_bookings
+ , subq_4.booking_value
+ , subq_4.max_booking_value
+ , subq_4.min_booking_value
+ , subq_4.bookers
+ , subq_4.average_booking_value
+ , subq_4.referred_bookings
+ , subq_4.median_booking_value
+ , subq_4.booking_value_p99
+ , subq_4.discrete_booking_value_p99
+ , subq_4.approximate_continuous_booking_value_p99
+ , subq_4.approximate_discrete_booking_value_p99
FROM (
- -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day']
+ -- Join to Time Spine Dataset
SELECT
- subq_4.metric_time__day
- , subq_4.booking__is_instant
- , subq_4.bookings
+ subq_2.metric_time__day AS metric_time__day
+ , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week
+ , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month
+ , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter
+ , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year
+ , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year
+ , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter
+ , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month
+ , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day
+ , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow
+ , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy
+ , subq_1.ds__day AS ds__day
+ , subq_1.ds__week AS ds__week
+ , subq_1.ds__month AS ds__month
+ , subq_1.ds__quarter AS ds__quarter
+ , subq_1.ds__year AS ds__year
+ , subq_1.ds__extract_year AS ds__extract_year
+ , subq_1.ds__extract_quarter AS ds__extract_quarter
+ , subq_1.ds__extract_month AS ds__extract_month
+ , subq_1.ds__extract_day AS ds__extract_day
+ , subq_1.ds__extract_dow AS ds__extract_dow
+ , subq_1.ds__extract_doy AS ds__extract_doy
+ , subq_1.ds_partitioned__day AS ds_partitioned__day
+ , subq_1.ds_partitioned__week AS ds_partitioned__week
+ , subq_1.ds_partitioned__month AS ds_partitioned__month
+ , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_1.ds_partitioned__year AS ds_partitioned__year
+ , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_1.paid_at__day AS paid_at__day
+ , subq_1.paid_at__week AS paid_at__week
+ , subq_1.paid_at__month AS paid_at__month
+ , subq_1.paid_at__quarter AS paid_at__quarter
+ , subq_1.paid_at__year AS paid_at__year
+ , subq_1.paid_at__extract_year AS paid_at__extract_year
+ , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_1.paid_at__extract_month AS paid_at__extract_month
+ , subq_1.paid_at__extract_day AS paid_at__extract_day
+ , subq_1.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_1.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_1.booking__ds__day AS booking__ds__day
+ , subq_1.booking__ds__week AS booking__ds__week
+ , subq_1.booking__ds__month AS booking__ds__month
+ , subq_1.booking__ds__quarter AS booking__ds__quarter
+ , subq_1.booking__ds__year AS booking__ds__year
+ , subq_1.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_1.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_1.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_1.booking__paid_at__day AS booking__paid_at__day
+ , subq_1.booking__paid_at__week AS booking__paid_at__week
+ , subq_1.booking__paid_at__month AS booking__paid_at__month
+ , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_1.booking__paid_at__year AS booking__paid_at__year
+ , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_1.listing AS listing
+ , subq_1.guest AS guest
+ , subq_1.host AS host
+ , subq_1.booking__listing AS booking__listing
+ , subq_1.booking__guest AS booking__guest
+ , subq_1.booking__host AS booking__host
+ , subq_1.is_instant AS is_instant
+ , subq_1.booking__is_instant AS booking__is_instant
+ , subq_1.bookings AS bookings
+ , subq_1.instant_bookings AS instant_bookings
+ , subq_1.booking_value AS booking_value
+ , subq_1.max_booking_value AS max_booking_value
+ , subq_1.min_booking_value AS min_booking_value
+ , subq_1.bookers AS bookers
+ , subq_1.average_booking_value AS average_booking_value
+ , subq_1.referred_bookings AS referred_bookings
+ , subq_1.median_booking_value AS median_booking_value
+ , subq_1.booking_value_p99 AS booking_value_p99
+ , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
FROM (
- -- Join to Time Spine Dataset
+ -- Time Spine
SELECT
- subq_2.metric_time__day AS metric_time__day
- , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week
- , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month
- , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter
- , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year
- , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year
- , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter
- , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month
- , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day
- , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow
- , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy
- , subq_1.ds__day AS ds__day
- , subq_1.ds__week AS ds__week
- , subq_1.ds__month AS ds__month
- , subq_1.ds__quarter AS ds__quarter
- , subq_1.ds__year AS ds__year
- , subq_1.ds__extract_year AS ds__extract_year
- , subq_1.ds__extract_quarter AS ds__extract_quarter
- , subq_1.ds__extract_month AS ds__extract_month
- , subq_1.ds__extract_day AS ds__extract_day
- , subq_1.ds__extract_dow AS ds__extract_dow
- , subq_1.ds__extract_doy AS ds__extract_doy
- , subq_1.ds_partitioned__day AS ds_partitioned__day
- , subq_1.ds_partitioned__week AS ds_partitioned__week
- , subq_1.ds_partitioned__month AS ds_partitioned__month
- , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter
- , subq_1.ds_partitioned__year AS ds_partitioned__year
- , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year
- , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
- , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month
- , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day
- , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
- , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
- , subq_1.paid_at__day AS paid_at__day
- , subq_1.paid_at__week AS paid_at__week
- , subq_1.paid_at__month AS paid_at__month
- , subq_1.paid_at__quarter AS paid_at__quarter
- , subq_1.paid_at__year AS paid_at__year
- , subq_1.paid_at__extract_year AS paid_at__extract_year
- , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter
- , subq_1.paid_at__extract_month AS paid_at__extract_month
- , subq_1.paid_at__extract_day AS paid_at__extract_day
- , subq_1.paid_at__extract_dow AS paid_at__extract_dow
- , subq_1.paid_at__extract_doy AS paid_at__extract_doy
- , subq_1.booking__ds__day AS booking__ds__day
- , subq_1.booking__ds__week AS booking__ds__week
- , subq_1.booking__ds__month AS booking__ds__month
- , subq_1.booking__ds__quarter AS booking__ds__quarter
- , subq_1.booking__ds__year AS booking__ds__year
- , subq_1.booking__ds__extract_year AS booking__ds__extract_year
- , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter
- , subq_1.booking__ds__extract_month AS booking__ds__extract_month
- , subq_1.booking__ds__extract_day AS booking__ds__extract_day
- , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow
- , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy
- , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day
- , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week
- , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month
- , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
- , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year
- , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
- , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
- , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
- , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
- , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
- , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
- , subq_1.booking__paid_at__day AS booking__paid_at__day
- , subq_1.booking__paid_at__week AS booking__paid_at__week
- , subq_1.booking__paid_at__month AS booking__paid_at__month
- , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter
- , subq_1.booking__paid_at__year AS booking__paid_at__year
- , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year
- , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
- , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month
- , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day
- , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
- , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
- , subq_1.listing AS listing
- , subq_1.guest AS guest
- , subq_1.host AS host
- , subq_1.booking__listing AS booking__listing
- , subq_1.booking__guest AS booking__guest
- , subq_1.booking__host AS booking__host
- , subq_1.is_instant AS is_instant
- , subq_1.booking__is_instant AS booking__is_instant
- , subq_1.bookings AS bookings
- , subq_1.instant_bookings AS instant_bookings
- , subq_1.booking_value AS booking_value
- , subq_1.max_booking_value AS max_booking_value
- , subq_1.min_booking_value AS min_booking_value
- , subq_1.bookers AS bookers
- , subq_1.average_booking_value AS average_booking_value
- , subq_1.referred_bookings AS referred_bookings
- , subq_1.median_booking_value AS median_booking_value
- , subq_1.booking_value_p99 AS booking_value_p99
- , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99
- , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
- , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ subq_3.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_3
+ ) subq_2
+ INNER JOIN (
+ -- 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 (
- -- Time Spine
- SELECT
- subq_3.ds AS metric_time__day
- FROM ***************************.mf_time_spine subq_3
- ) subq_2
- INNER JOIN (
- -- Metric Time Dimension 'ds'
+ -- Read Elements From Semantic Model 'bookings_source'
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
- ON
- subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day
- ) subq_4
- ) subq_5
- GROUP BY
- subq_5.metric_time__day
- , subq_5.booking__is_instant
- ) subq_6
- ) subq_7
- ) subq_8
- ON
- subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day
- ) subq_11
- WHERE booking__is_instant
- ) subq_12
-) subq_13
+ 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
+ ON
+ subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day
+ ) subq_4
+ WHERE booking__is_instant
+ ) subq_5
+ ) subq_6
+ GROUP BY
+ subq_6.metric_time__day
+ ) subq_7
+ ) subq_8
+ ) subq_9
+ ON
+ subq_10.metric_time__day - INTERVAL 2 day = subq_9.metric_time__day
+) subq_12
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql
index d62752cb4..d3844ccde 100644
--- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql
@@ -7,34 +7,31 @@ SELECT
metric_time__day
, 2 * bookings_offset_once AS bookings_offset_twice
FROM (
- -- Constrain Output with WHERE
- -- Pass Only Elements: ['metric_time__day', 'bookings_offset_once']
+ -- Join to Time Spine Dataset
SELECT
- metric_time__day
- , bookings_offset_once
- FROM (
- -- Join to Time Spine Dataset
+ subq_24.ds AS metric_time__day
+ , subq_22.bookings_offset_once AS bookings_offset_once
+ FROM ***************************.mf_time_spine subq_24
+ INNER JOIN (
+ -- Compute Metrics via Expressions
SELECT
- subq_24.ds AS metric_time__day
- , subq_22.booking__is_instant AS booking__is_instant
- , subq_22.bookings_offset_once AS bookings_offset_once
- FROM ***************************.mf_time_spine subq_24
- INNER JOIN (
+ metric_time__day
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
+ -- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
metric_time__day
- , booking__is_instant
- , 2 * bookings AS bookings_offset_once
+ , SUM(bookings) AS bookings
FROM (
-- Join to Time Spine Dataset
- -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day']
- -- Aggregate Measures
- -- Compute Metrics via Expressions
SELECT
- subq_17.ds AS metric_time__day
- , subq_15.booking__is_instant AS booking__is_instant
- , SUM(subq_15.bookings) AS bookings
- FROM ***************************.mf_time_spine subq_17
+ subq_16.ds AS metric_time__day
+ , subq_14.booking__is_instant AS booking__is_instant
+ , subq_14.bookings AS bookings
+ FROM ***************************.mf_time_spine subq_16
INNER JOIN (
-- Read Elements From Semantic Model 'bookings_source'
-- Metric Time Dimension 'ds'
@@ -43,16 +40,15 @@ FROM (
, is_instant AS booking__is_instant
, 1 AS bookings
FROM ***************************.fct_bookings bookings_source_src_28000
- ) subq_15
+ ) subq_14
ON
- subq_17.ds - INTERVAL 5 day = subq_15.metric_time__day
- GROUP BY
- subq_17.ds
- , subq_15.booking__is_instant
- ) subq_21
- ) subq_22
- ON
- subq_24.ds - INTERVAL 2 day = subq_22.metric_time__day
- ) subq_25
- WHERE booking__is_instant
-) subq_27
+ subq_16.ds - INTERVAL 5 day = subq_14.metric_time__day
+ ) subq_17
+ WHERE booking__is_instant
+ GROUP BY
+ metric_time__day
+ ) subq_21
+ ) subq_22
+ ON
+ subq_24.ds - INTERVAL 2 day = subq_22.metric_time__day
+) subq_25
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_to_grain_metric_with_tiered_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_to_grain_metric_with_tiered_filters__plan0.sql
new file mode 100644
index 000000000..75b3417f5
--- /dev/null
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_to_grain_metric_with_tiered_filters__plan0.sql
@@ -0,0 +1,1623 @@
+test_name: test_nested_offset_to_grain_metric_with_tiered_filters
+test_filename: test_derived_metric_rendering.py
+docstring:
+ Tests that filters at different tiers are applied appropriately for derived metrics with offset to grain.
+sql_engine: DuckDB
+---
+-- Compute Metrics via Expressions
+SELECT
+ subq_36.metric_time__day
+ , bookings_this_month_wtd - bookings AS bookings_offset_to_grain_twice_with_tiered_filters
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_5.metric_time__day, subq_35.metric_time__day) AS metric_time__day
+ , MAX(subq_5.bookings) AS bookings
+ , MAX(subq_35.bookings_this_month_wtd) AS bookings_this_month_wtd
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_4.metric_time__day
+ , subq_4.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_3.metric_time__day
+ , SUM(subq_3.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.bookings
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ 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_partitioned__day
+ , subq_1.ds_partitioned__week
+ , subq_1.ds_partitioned__month
+ , subq_1.ds_partitioned__quarter
+ , subq_1.ds_partitioned__year
+ , subq_1.ds_partitioned__extract_year
+ , subq_1.ds_partitioned__extract_quarter
+ , subq_1.ds_partitioned__extract_month
+ , subq_1.ds_partitioned__extract_day
+ , subq_1.ds_partitioned__extract_dow
+ , subq_1.ds_partitioned__extract_doy
+ , subq_1.paid_at__day
+ , subq_1.paid_at__week
+ , subq_1.paid_at__month
+ , subq_1.paid_at__quarter
+ , subq_1.paid_at__year
+ , subq_1.paid_at__extract_year
+ , subq_1.paid_at__extract_quarter
+ , subq_1.paid_at__extract_month
+ , subq_1.paid_at__extract_day
+ , subq_1.paid_at__extract_dow
+ , subq_1.paid_at__extract_doy
+ , subq_1.booking__ds__day
+ , subq_1.booking__ds__week
+ , subq_1.booking__ds__month
+ , subq_1.booking__ds__quarter
+ , subq_1.booking__ds__year
+ , subq_1.booking__ds__extract_year
+ , subq_1.booking__ds__extract_quarter
+ , subq_1.booking__ds__extract_month
+ , subq_1.booking__ds__extract_day
+ , subq_1.booking__ds__extract_dow
+ , subq_1.booking__ds__extract_doy
+ , subq_1.booking__ds_partitioned__day
+ , subq_1.booking__ds_partitioned__week
+ , subq_1.booking__ds_partitioned__month
+ , subq_1.booking__ds_partitioned__quarter
+ , subq_1.booking__ds_partitioned__year
+ , subq_1.booking__ds_partitioned__extract_year
+ , subq_1.booking__ds_partitioned__extract_quarter
+ , subq_1.booking__ds_partitioned__extract_month
+ , subq_1.booking__ds_partitioned__extract_day
+ , subq_1.booking__ds_partitioned__extract_dow
+ , subq_1.booking__ds_partitioned__extract_doy
+ , subq_1.booking__paid_at__day
+ , subq_1.booking__paid_at__week
+ , subq_1.booking__paid_at__month
+ , subq_1.booking__paid_at__quarter
+ , subq_1.booking__paid_at__year
+ , subq_1.booking__paid_at__extract_year
+ , subq_1.booking__paid_at__extract_quarter
+ , subq_1.booking__paid_at__extract_month
+ , subq_1.booking__paid_at__extract_day
+ , subq_1.booking__paid_at__extract_dow
+ , subq_1.booking__paid_at__extract_doy
+ , subq_1.metric_time__day
+ , subq_1.metric_time__week
+ , subq_1.metric_time__month
+ , subq_1.metric_time__quarter
+ , subq_1.metric_time__year
+ , subq_1.metric_time__extract_year
+ , subq_1.metric_time__extract_quarter
+ , subq_1.metric_time__extract_month
+ , subq_1.metric_time__extract_day
+ , subq_1.metric_time__extract_dow
+ , subq_1.metric_time__extract_doy
+ , subq_1.listing
+ , subq_1.guest
+ , subq_1.host
+ , subq_1.booking__listing
+ , subq_1.booking__guest
+ , subq_1.booking__host
+ , subq_1.is_instant
+ , subq_1.booking__is_instant
+ , subq_1.bookings
+ , subq_1.instant_bookings
+ , subq_1.booking_value
+ , subq_1.max_booking_value
+ , subq_1.min_booking_value
+ , subq_1.bookers
+ , subq_1.average_booking_value
+ , subq_1.referred_bookings
+ , subq_1.median_booking_value
+ , subq_1.booking_value_p99
+ , subq_1.discrete_booking_value_p99
+ , subq_1.approximate_continuous_booking_value_p99
+ , subq_1.approximate_discrete_booking_value_p99
+ 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
+ WHERE (((listing IS NOT NULL) AND (metric_time__quarter >= '2020-01-01')) AND (metric_time__month >= '2020-01-01')) AND (booking__is_instant)
+ ) subq_2
+ ) subq_3
+ GROUP BY
+ subq_3.metric_time__day
+ ) subq_4
+ ) subq_5
+ FULL OUTER JOIN (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_32.metric_time__day AS metric_time__day
+ , subq_31.bookings_this_month_wtd AS bookings_this_month_wtd
+ FROM (
+ -- Filter Time Spine
+ SELECT
+ subq_34.metric_time__day
+ FROM (
+ -- Time Spine
+ SELECT
+ subq_33.ds AS metric_time__day
+ , DATE_TRUNC('month', subq_33.ds) AS metric_time__month
+ , DATE_TRUNC('quarter', subq_33.ds) AS metric_time__quarter
+ FROM ***************************.mf_time_spine subq_33
+ ) subq_34
+ WHERE (
+ metric_time__quarter >= '2020-01-01'
+ ) AND (
+ metric_time__month >= '2020-01-01'
+ )
+ ) subq_32
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_30.metric_time__day
+ , bookings - bookings_at_start_of_month AS bookings_this_month_wtd
+ FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_15.metric_time__day, subq_29.metric_time__day) AS metric_time__day
+ , MAX(subq_15.bookings) AS bookings
+ , MAX(subq_29.bookings_at_start_of_month) AS bookings_at_start_of_month
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_14.metric_time__day
+ , subq_14.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_13.metric_time__day
+ , SUM(subq_13.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
+ SELECT
+ subq_12.metric_time__day
+ , subq_12.bookings
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_11.ds__day
+ , subq_11.ds__week
+ , subq_11.ds__month
+ , subq_11.ds__quarter
+ , subq_11.ds__year
+ , subq_11.ds__extract_year
+ , subq_11.ds__extract_quarter
+ , subq_11.ds__extract_month
+ , subq_11.ds__extract_day
+ , subq_11.ds__extract_dow
+ , subq_11.ds__extract_doy
+ , subq_11.ds_partitioned__day
+ , subq_11.ds_partitioned__week
+ , subq_11.ds_partitioned__month
+ , subq_11.ds_partitioned__quarter
+ , subq_11.ds_partitioned__year
+ , subq_11.ds_partitioned__extract_year
+ , subq_11.ds_partitioned__extract_quarter
+ , subq_11.ds_partitioned__extract_month
+ , subq_11.ds_partitioned__extract_day
+ , subq_11.ds_partitioned__extract_dow
+ , subq_11.ds_partitioned__extract_doy
+ , subq_11.paid_at__day
+ , subq_11.paid_at__week
+ , subq_11.paid_at__month
+ , subq_11.paid_at__quarter
+ , subq_11.paid_at__year
+ , subq_11.paid_at__extract_year
+ , subq_11.paid_at__extract_quarter
+ , subq_11.paid_at__extract_month
+ , subq_11.paid_at__extract_day
+ , subq_11.paid_at__extract_dow
+ , subq_11.paid_at__extract_doy
+ , subq_11.booking__ds__day
+ , subq_11.booking__ds__week
+ , subq_11.booking__ds__month
+ , subq_11.booking__ds__quarter
+ , subq_11.booking__ds__year
+ , subq_11.booking__ds__extract_year
+ , subq_11.booking__ds__extract_quarter
+ , subq_11.booking__ds__extract_month
+ , subq_11.booking__ds__extract_day
+ , subq_11.booking__ds__extract_dow
+ , subq_11.booking__ds__extract_doy
+ , subq_11.booking__ds_partitioned__day
+ , subq_11.booking__ds_partitioned__week
+ , subq_11.booking__ds_partitioned__month
+ , subq_11.booking__ds_partitioned__quarter
+ , subq_11.booking__ds_partitioned__year
+ , subq_11.booking__ds_partitioned__extract_year
+ , subq_11.booking__ds_partitioned__extract_quarter
+ , subq_11.booking__ds_partitioned__extract_month
+ , subq_11.booking__ds_partitioned__extract_day
+ , subq_11.booking__ds_partitioned__extract_dow
+ , subq_11.booking__ds_partitioned__extract_doy
+ , subq_11.booking__paid_at__day
+ , subq_11.booking__paid_at__week
+ , subq_11.booking__paid_at__month
+ , subq_11.booking__paid_at__quarter
+ , subq_11.booking__paid_at__year
+ , subq_11.booking__paid_at__extract_year
+ , subq_11.booking__paid_at__extract_quarter
+ , subq_11.booking__paid_at__extract_month
+ , subq_11.booking__paid_at__extract_day
+ , subq_11.booking__paid_at__extract_dow
+ , subq_11.booking__paid_at__extract_doy
+ , subq_11.metric_time__day
+ , subq_11.metric_time__week
+ , subq_11.metric_time__month
+ , subq_11.metric_time__quarter
+ , subq_11.metric_time__year
+ , subq_11.metric_time__extract_year
+ , subq_11.metric_time__extract_quarter
+ , subq_11.metric_time__extract_month
+ , subq_11.metric_time__extract_day
+ , subq_11.metric_time__extract_dow
+ , subq_11.metric_time__extract_doy
+ , subq_11.listing__created_at__day
+ , subq_11.listing
+ , subq_11.guest
+ , subq_11.host
+ , subq_11.booking__listing
+ , subq_11.booking__guest
+ , subq_11.booking__host
+ , subq_11.is_instant
+ , subq_11.booking__is_instant
+ , subq_11.bookings
+ , subq_11.instant_bookings
+ , subq_11.booking_value
+ , subq_11.max_booking_value
+ , subq_11.min_booking_value
+ , subq_11.bookers
+ , subq_11.average_booking_value
+ , subq_11.referred_bookings
+ , subq_11.median_booking_value
+ , subq_11.booking_value_p99
+ , subq_11.discrete_booking_value_p99
+ , subq_11.approximate_continuous_booking_value_p99
+ , subq_11.approximate_discrete_booking_value_p99
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_10.created_at__day AS listing__created_at__day
+ , subq_7.ds__day AS ds__day
+ , subq_7.ds__week AS ds__week
+ , subq_7.ds__month AS ds__month
+ , subq_7.ds__quarter AS ds__quarter
+ , subq_7.ds__year AS ds__year
+ , subq_7.ds__extract_year AS ds__extract_year
+ , subq_7.ds__extract_quarter AS ds__extract_quarter
+ , subq_7.ds__extract_month AS ds__extract_month
+ , subq_7.ds__extract_day AS ds__extract_day
+ , subq_7.ds__extract_dow AS ds__extract_dow
+ , subq_7.ds__extract_doy AS ds__extract_doy
+ , subq_7.ds_partitioned__day AS ds_partitioned__day
+ , subq_7.ds_partitioned__week AS ds_partitioned__week
+ , subq_7.ds_partitioned__month AS ds_partitioned__month
+ , subq_7.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_7.ds_partitioned__year AS ds_partitioned__year
+ , subq_7.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_7.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_7.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_7.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_7.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_7.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_7.paid_at__day AS paid_at__day
+ , subq_7.paid_at__week AS paid_at__week
+ , subq_7.paid_at__month AS paid_at__month
+ , subq_7.paid_at__quarter AS paid_at__quarter
+ , subq_7.paid_at__year AS paid_at__year
+ , subq_7.paid_at__extract_year AS paid_at__extract_year
+ , subq_7.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_7.paid_at__extract_month AS paid_at__extract_month
+ , subq_7.paid_at__extract_day AS paid_at__extract_day
+ , subq_7.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_7.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_7.booking__ds__day AS booking__ds__day
+ , subq_7.booking__ds__week AS booking__ds__week
+ , subq_7.booking__ds__month AS booking__ds__month
+ , subq_7.booking__ds__quarter AS booking__ds__quarter
+ , subq_7.booking__ds__year AS booking__ds__year
+ , subq_7.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_7.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_7.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_7.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_7.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_7.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_7.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_7.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_7.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_7.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_7.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_7.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_7.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_7.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_7.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_7.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_7.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_7.booking__paid_at__day AS booking__paid_at__day
+ , subq_7.booking__paid_at__week AS booking__paid_at__week
+ , subq_7.booking__paid_at__month AS booking__paid_at__month
+ , subq_7.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_7.booking__paid_at__year AS booking__paid_at__year
+ , subq_7.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_7.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_7.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_7.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_7.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_7.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_7.metric_time__day AS metric_time__day
+ , subq_7.metric_time__week AS metric_time__week
+ , subq_7.metric_time__month AS metric_time__month
+ , subq_7.metric_time__quarter AS metric_time__quarter
+ , subq_7.metric_time__year AS metric_time__year
+ , subq_7.metric_time__extract_year AS metric_time__extract_year
+ , subq_7.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_7.metric_time__extract_month AS metric_time__extract_month
+ , subq_7.metric_time__extract_day AS metric_time__extract_day
+ , subq_7.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_7.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_7.listing AS listing
+ , subq_7.guest AS guest
+ , subq_7.host AS host
+ , subq_7.booking__listing AS booking__listing
+ , subq_7.booking__guest AS booking__guest
+ , subq_7.booking__host AS booking__host
+ , subq_7.is_instant AS is_instant
+ , subq_7.booking__is_instant AS booking__is_instant
+ , subq_7.bookings AS bookings
+ , subq_7.instant_bookings AS instant_bookings
+ , subq_7.booking_value AS booking_value
+ , subq_7.max_booking_value AS max_booking_value
+ , subq_7.min_booking_value AS min_booking_value
+ , subq_7.bookers AS bookers
+ , subq_7.average_booking_value AS average_booking_value
+ , subq_7.referred_bookings AS referred_bookings
+ , subq_7.median_booking_value AS median_booking_value
+ , subq_7.booking_value_p99 AS booking_value_p99
+ , subq_7.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_7.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_7.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- 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
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['created_at__day', 'listing']
+ SELECT
+ subq_9.created_at__day
+ , subq_9.listing
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.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.ds__day AS metric_time__day
+ , subq_8.ds__week AS metric_time__week
+ , subq_8.ds__month AS metric_time__month
+ , subq_8.ds__quarter AS metric_time__quarter
+ , subq_8.ds__year AS metric_time__year
+ , subq_8.ds__extract_year AS metric_time__extract_year
+ , subq_8.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_8.ds__extract_month AS metric_time__extract_month
+ , subq_8.ds__extract_day AS metric_time__extract_day
+ , subq_8.ds__extract_dow AS metric_time__extract_dow
+ , subq_8.ds__extract_doy AS metric_time__extract_doy
+ , subq_8.listing
+ , subq_8.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.listings
+ , subq_8.largest_listing
+ , subq_8.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_8
+ ) subq_9
+ ) subq_10
+ ON
+ subq_7.listing = subq_10.listing
+ ) subq_11
+ WHERE (((listing IS NOT NULL) AND (booking__is_instant)) AND (booking__ds__year >= '2019-01-01')) AND (listing__created_at__day >= '2020-01-02')
+ ) subq_12
+ ) subq_13
+ GROUP BY
+ subq_13.metric_time__day
+ ) subq_14
+ ) subq_15
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_28.metric_time__day
+ , subq_28.bookings AS bookings_at_start_of_month
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_27.metric_time__day
+ , SUM(subq_27.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
+ SELECT
+ subq_26.metric_time__day
+ , subq_26.bookings
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_25.metric_time__day
+ , subq_25.metric_time__week
+ , subq_25.metric_time__month
+ , subq_25.metric_time__quarter
+ , subq_25.metric_time__year
+ , subq_25.metric_time__extract_year
+ , subq_25.metric_time__extract_quarter
+ , subq_25.metric_time__extract_month
+ , subq_25.metric_time__extract_day
+ , subq_25.metric_time__extract_dow
+ , subq_25.metric_time__extract_doy
+ , subq_25.ds__day
+ , subq_25.ds__week
+ , subq_25.ds__month
+ , subq_25.ds__quarter
+ , subq_25.ds__year
+ , subq_25.ds__extract_year
+ , subq_25.ds__extract_quarter
+ , subq_25.ds__extract_month
+ , subq_25.ds__extract_day
+ , subq_25.ds__extract_dow
+ , subq_25.ds__extract_doy
+ , subq_25.ds_partitioned__day
+ , subq_25.ds_partitioned__week
+ , subq_25.ds_partitioned__month
+ , subq_25.ds_partitioned__quarter
+ , subq_25.ds_partitioned__year
+ , subq_25.ds_partitioned__extract_year
+ , subq_25.ds_partitioned__extract_quarter
+ , subq_25.ds_partitioned__extract_month
+ , subq_25.ds_partitioned__extract_day
+ , subq_25.ds_partitioned__extract_dow
+ , subq_25.ds_partitioned__extract_doy
+ , subq_25.paid_at__day
+ , subq_25.paid_at__week
+ , subq_25.paid_at__month
+ , subq_25.paid_at__quarter
+ , subq_25.paid_at__year
+ , subq_25.paid_at__extract_year
+ , subq_25.paid_at__extract_quarter
+ , subq_25.paid_at__extract_month
+ , subq_25.paid_at__extract_day
+ , subq_25.paid_at__extract_dow
+ , subq_25.paid_at__extract_doy
+ , subq_25.booking__ds__day
+ , subq_25.booking__ds__week
+ , subq_25.booking__ds__month
+ , subq_25.booking__ds__quarter
+ , subq_25.booking__ds__year
+ , subq_25.booking__ds__extract_year
+ , subq_25.booking__ds__extract_quarter
+ , subq_25.booking__ds__extract_month
+ , subq_25.booking__ds__extract_day
+ , subq_25.booking__ds__extract_dow
+ , subq_25.booking__ds__extract_doy
+ , subq_25.booking__ds_partitioned__day
+ , subq_25.booking__ds_partitioned__week
+ , subq_25.booking__ds_partitioned__month
+ , subq_25.booking__ds_partitioned__quarter
+ , subq_25.booking__ds_partitioned__year
+ , subq_25.booking__ds_partitioned__extract_year
+ , subq_25.booking__ds_partitioned__extract_quarter
+ , subq_25.booking__ds_partitioned__extract_month
+ , subq_25.booking__ds_partitioned__extract_day
+ , subq_25.booking__ds_partitioned__extract_dow
+ , subq_25.booking__ds_partitioned__extract_doy
+ , subq_25.booking__paid_at__day
+ , subq_25.booking__paid_at__week
+ , subq_25.booking__paid_at__month
+ , subq_25.booking__paid_at__quarter
+ , subq_25.booking__paid_at__year
+ , subq_25.booking__paid_at__extract_year
+ , subq_25.booking__paid_at__extract_quarter
+ , subq_25.booking__paid_at__extract_month
+ , subq_25.booking__paid_at__extract_day
+ , subq_25.booking__paid_at__extract_dow
+ , subq_25.booking__paid_at__extract_doy
+ , subq_25.listing__created_at__day
+ , subq_25.listing
+ , subq_25.guest
+ , subq_25.host
+ , subq_25.booking__listing
+ , subq_25.booking__guest
+ , subq_25.booking__host
+ , subq_25.is_instant
+ , subq_25.booking__is_instant
+ , subq_25.bookings
+ , subq_25.instant_bookings
+ , subq_25.booking_value
+ , subq_25.max_booking_value
+ , subq_25.min_booking_value
+ , subq_25.bookers
+ , subq_25.average_booking_value
+ , subq_25.referred_bookings
+ , subq_25.median_booking_value
+ , subq_25.booking_value_p99
+ , subq_25.discrete_booking_value_p99
+ , subq_25.approximate_continuous_booking_value_p99
+ , subq_25.approximate_discrete_booking_value_p99
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_24.created_at__day AS listing__created_at__day
+ , subq_21.metric_time__day AS metric_time__day
+ , subq_21.metric_time__week AS metric_time__week
+ , subq_21.metric_time__month AS metric_time__month
+ , subq_21.metric_time__quarter AS metric_time__quarter
+ , subq_21.metric_time__year AS metric_time__year
+ , subq_21.metric_time__extract_year AS metric_time__extract_year
+ , subq_21.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_21.metric_time__extract_month AS metric_time__extract_month
+ , subq_21.metric_time__extract_day AS metric_time__extract_day
+ , subq_21.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_21.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_21.ds__day AS ds__day
+ , subq_21.ds__week AS ds__week
+ , subq_21.ds__month AS ds__month
+ , subq_21.ds__quarter AS ds__quarter
+ , subq_21.ds__year AS ds__year
+ , subq_21.ds__extract_year AS ds__extract_year
+ , subq_21.ds__extract_quarter AS ds__extract_quarter
+ , subq_21.ds__extract_month AS ds__extract_month
+ , subq_21.ds__extract_day AS ds__extract_day
+ , subq_21.ds__extract_dow AS ds__extract_dow
+ , subq_21.ds__extract_doy AS ds__extract_doy
+ , subq_21.ds_partitioned__day AS ds_partitioned__day
+ , subq_21.ds_partitioned__week AS ds_partitioned__week
+ , subq_21.ds_partitioned__month AS ds_partitioned__month
+ , subq_21.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_21.ds_partitioned__year AS ds_partitioned__year
+ , subq_21.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_21.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_21.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_21.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_21.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_21.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_21.paid_at__day AS paid_at__day
+ , subq_21.paid_at__week AS paid_at__week
+ , subq_21.paid_at__month AS paid_at__month
+ , subq_21.paid_at__quarter AS paid_at__quarter
+ , subq_21.paid_at__year AS paid_at__year
+ , subq_21.paid_at__extract_year AS paid_at__extract_year
+ , subq_21.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_21.paid_at__extract_month AS paid_at__extract_month
+ , subq_21.paid_at__extract_day AS paid_at__extract_day
+ , subq_21.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_21.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_21.booking__ds__day AS booking__ds__day
+ , subq_21.booking__ds__week AS booking__ds__week
+ , subq_21.booking__ds__month AS booking__ds__month
+ , subq_21.booking__ds__quarter AS booking__ds__quarter
+ , subq_21.booking__ds__year AS booking__ds__year
+ , subq_21.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_21.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_21.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_21.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_21.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_21.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_21.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_21.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_21.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_21.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_21.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_21.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_21.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_21.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_21.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_21.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_21.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_21.booking__paid_at__day AS booking__paid_at__day
+ , subq_21.booking__paid_at__week AS booking__paid_at__week
+ , subq_21.booking__paid_at__month AS booking__paid_at__month
+ , subq_21.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_21.booking__paid_at__year AS booking__paid_at__year
+ , subq_21.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_21.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_21.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_21.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_21.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_21.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_21.listing AS listing
+ , subq_21.guest AS guest
+ , subq_21.host AS host
+ , subq_21.booking__listing AS booking__listing
+ , subq_21.booking__guest AS booking__guest
+ , subq_21.booking__host AS booking__host
+ , subq_21.is_instant AS is_instant
+ , subq_21.booking__is_instant AS booking__is_instant
+ , subq_21.bookings AS bookings
+ , subq_21.instant_bookings AS instant_bookings
+ , subq_21.booking_value AS booking_value
+ , subq_21.max_booking_value AS max_booking_value
+ , subq_21.min_booking_value AS min_booking_value
+ , subq_21.bookers AS bookers
+ , subq_21.average_booking_value AS average_booking_value
+ , subq_21.referred_bookings AS referred_bookings
+ , subq_21.median_booking_value AS median_booking_value
+ , subq_21.booking_value_p99 AS booking_value_p99
+ , subq_21.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_21.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_21.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_18.metric_time__day AS metric_time__day
+ , DATE_TRUNC('week', subq_18.metric_time__day) AS metric_time__week
+ , DATE_TRUNC('month', subq_18.metric_time__day) AS metric_time__month
+ , DATE_TRUNC('quarter', subq_18.metric_time__day) AS metric_time__quarter
+ , DATE_TRUNC('year', subq_18.metric_time__day) AS metric_time__year
+ , EXTRACT(year FROM subq_18.metric_time__day) AS metric_time__extract_year
+ , EXTRACT(quarter FROM subq_18.metric_time__day) AS metric_time__extract_quarter
+ , EXTRACT(month FROM subq_18.metric_time__day) AS metric_time__extract_month
+ , EXTRACT(day FROM subq_18.metric_time__day) AS metric_time__extract_day
+ , EXTRACT(isodow FROM subq_18.metric_time__day) AS metric_time__extract_dow
+ , EXTRACT(doy FROM subq_18.metric_time__day) AS metric_time__extract_doy
+ , subq_17.ds__day AS ds__day
+ , subq_17.ds__week AS ds__week
+ , subq_17.ds__month AS ds__month
+ , subq_17.ds__quarter AS ds__quarter
+ , subq_17.ds__year AS ds__year
+ , subq_17.ds__extract_year AS ds__extract_year
+ , subq_17.ds__extract_quarter AS ds__extract_quarter
+ , subq_17.ds__extract_month AS ds__extract_month
+ , subq_17.ds__extract_day AS ds__extract_day
+ , subq_17.ds__extract_dow AS ds__extract_dow
+ , subq_17.ds__extract_doy AS ds__extract_doy
+ , subq_17.ds_partitioned__day AS ds_partitioned__day
+ , subq_17.ds_partitioned__week AS ds_partitioned__week
+ , subq_17.ds_partitioned__month AS ds_partitioned__month
+ , subq_17.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_17.ds_partitioned__year AS ds_partitioned__year
+ , subq_17.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_17.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_17.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_17.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_17.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_17.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_17.paid_at__day AS paid_at__day
+ , subq_17.paid_at__week AS paid_at__week
+ , subq_17.paid_at__month AS paid_at__month
+ , subq_17.paid_at__quarter AS paid_at__quarter
+ , subq_17.paid_at__year AS paid_at__year
+ , subq_17.paid_at__extract_year AS paid_at__extract_year
+ , subq_17.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_17.paid_at__extract_month AS paid_at__extract_month
+ , subq_17.paid_at__extract_day AS paid_at__extract_day
+ , subq_17.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_17.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_17.booking__ds__day AS booking__ds__day
+ , subq_17.booking__ds__week AS booking__ds__week
+ , subq_17.booking__ds__month AS booking__ds__month
+ , subq_17.booking__ds__quarter AS booking__ds__quarter
+ , subq_17.booking__ds__year AS booking__ds__year
+ , subq_17.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_17.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_17.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_17.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_17.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_17.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_17.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_17.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_17.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_17.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_17.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_17.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_17.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_17.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_17.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_17.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_17.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_17.booking__paid_at__day AS booking__paid_at__day
+ , subq_17.booking__paid_at__week AS booking__paid_at__week
+ , subq_17.booking__paid_at__month AS booking__paid_at__month
+ , subq_17.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_17.booking__paid_at__year AS booking__paid_at__year
+ , subq_17.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_17.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_17.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_17.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_17.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_17.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_17.listing AS listing
+ , subq_17.guest AS guest
+ , subq_17.host AS host
+ , subq_17.booking__listing AS booking__listing
+ , subq_17.booking__guest AS booking__guest
+ , subq_17.booking__host AS booking__host
+ , subq_17.is_instant AS is_instant
+ , subq_17.booking__is_instant AS booking__is_instant
+ , subq_17.bookings AS bookings
+ , subq_17.instant_bookings AS instant_bookings
+ , subq_17.booking_value AS booking_value
+ , subq_17.max_booking_value AS max_booking_value
+ , subq_17.min_booking_value AS min_booking_value
+ , subq_17.bookers AS bookers
+ , subq_17.average_booking_value AS average_booking_value
+ , subq_17.referred_bookings AS referred_bookings
+ , subq_17.median_booking_value AS median_booking_value
+ , subq_17.booking_value_p99 AS booking_value_p99
+ , subq_17.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_17.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_17.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Filter Time Spine
+ SELECT
+ subq_20.metric_time__day
+ FROM (
+ -- Time Spine
+ SELECT
+ DATE_TRUNC('year', subq_19.ds) AS booking__ds__year
+ , subq_19.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_19
+ ) subq_20
+ WHERE booking__ds__year >= '2019-01-01'
+ ) subq_18
+ INNER JOIN (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_16.ds__day
+ , subq_16.ds__week
+ , subq_16.ds__month
+ , subq_16.ds__quarter
+ , subq_16.ds__year
+ , subq_16.ds__extract_year
+ , subq_16.ds__extract_quarter
+ , subq_16.ds__extract_month
+ , subq_16.ds__extract_day
+ , subq_16.ds__extract_dow
+ , subq_16.ds__extract_doy
+ , subq_16.ds_partitioned__day
+ , subq_16.ds_partitioned__week
+ , subq_16.ds_partitioned__month
+ , subq_16.ds_partitioned__quarter
+ , subq_16.ds_partitioned__year
+ , subq_16.ds_partitioned__extract_year
+ , subq_16.ds_partitioned__extract_quarter
+ , subq_16.ds_partitioned__extract_month
+ , subq_16.ds_partitioned__extract_day
+ , subq_16.ds_partitioned__extract_dow
+ , subq_16.ds_partitioned__extract_doy
+ , subq_16.paid_at__day
+ , subq_16.paid_at__week
+ , subq_16.paid_at__month
+ , subq_16.paid_at__quarter
+ , subq_16.paid_at__year
+ , subq_16.paid_at__extract_year
+ , subq_16.paid_at__extract_quarter
+ , subq_16.paid_at__extract_month
+ , subq_16.paid_at__extract_day
+ , subq_16.paid_at__extract_dow
+ , subq_16.paid_at__extract_doy
+ , subq_16.booking__ds__day
+ , subq_16.booking__ds__week
+ , subq_16.booking__ds__month
+ , subq_16.booking__ds__quarter
+ , subq_16.booking__ds__year
+ , subq_16.booking__ds__extract_year
+ , subq_16.booking__ds__extract_quarter
+ , subq_16.booking__ds__extract_month
+ , subq_16.booking__ds__extract_day
+ , subq_16.booking__ds__extract_dow
+ , subq_16.booking__ds__extract_doy
+ , subq_16.booking__ds_partitioned__day
+ , subq_16.booking__ds_partitioned__week
+ , subq_16.booking__ds_partitioned__month
+ , subq_16.booking__ds_partitioned__quarter
+ , subq_16.booking__ds_partitioned__year
+ , subq_16.booking__ds_partitioned__extract_year
+ , subq_16.booking__ds_partitioned__extract_quarter
+ , subq_16.booking__ds_partitioned__extract_month
+ , subq_16.booking__ds_partitioned__extract_day
+ , subq_16.booking__ds_partitioned__extract_dow
+ , subq_16.booking__ds_partitioned__extract_doy
+ , subq_16.booking__paid_at__day
+ , subq_16.booking__paid_at__week
+ , subq_16.booking__paid_at__month
+ , subq_16.booking__paid_at__quarter
+ , subq_16.booking__paid_at__year
+ , subq_16.booking__paid_at__extract_year
+ , subq_16.booking__paid_at__extract_quarter
+ , subq_16.booking__paid_at__extract_month
+ , subq_16.booking__paid_at__extract_day
+ , subq_16.booking__paid_at__extract_dow
+ , subq_16.booking__paid_at__extract_doy
+ , subq_16.ds__day AS metric_time__day
+ , subq_16.ds__week AS metric_time__week
+ , subq_16.ds__month AS metric_time__month
+ , subq_16.ds__quarter AS metric_time__quarter
+ , subq_16.ds__year AS metric_time__year
+ , subq_16.ds__extract_year AS metric_time__extract_year
+ , subq_16.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_16.ds__extract_month AS metric_time__extract_month
+ , subq_16.ds__extract_day AS metric_time__extract_day
+ , subq_16.ds__extract_dow AS metric_time__extract_dow
+ , subq_16.ds__extract_doy AS metric_time__extract_doy
+ , subq_16.listing
+ , subq_16.guest
+ , subq_16.host
+ , subq_16.booking__listing
+ , subq_16.booking__guest
+ , subq_16.booking__host
+ , subq_16.is_instant
+ , subq_16.booking__is_instant
+ , subq_16.bookings
+ , subq_16.instant_bookings
+ , subq_16.booking_value
+ , subq_16.max_booking_value
+ , subq_16.min_booking_value
+ , subq_16.bookers
+ , subq_16.average_booking_value
+ , subq_16.referred_bookings
+ , subq_16.median_booking_value
+ , subq_16.booking_value_p99
+ , subq_16.discrete_booking_value_p99
+ , subq_16.approximate_continuous_booking_value_p99
+ , subq_16.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_16
+ ) subq_17
+ ON
+ DATE_TRUNC('month', subq_18.metric_time__day) = subq_17.metric_time__day
+ ) subq_21
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['created_at__day', 'listing']
+ SELECT
+ subq_23.created_at__day
+ , subq_23.listing
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_22.ds__day
+ , subq_22.ds__week
+ , subq_22.ds__month
+ , subq_22.ds__quarter
+ , subq_22.ds__year
+ , subq_22.ds__extract_year
+ , subq_22.ds__extract_quarter
+ , subq_22.ds__extract_month
+ , subq_22.ds__extract_day
+ , subq_22.ds__extract_dow
+ , subq_22.ds__extract_doy
+ , subq_22.created_at__day
+ , subq_22.created_at__week
+ , subq_22.created_at__month
+ , subq_22.created_at__quarter
+ , subq_22.created_at__year
+ , subq_22.created_at__extract_year
+ , subq_22.created_at__extract_quarter
+ , subq_22.created_at__extract_month
+ , subq_22.created_at__extract_day
+ , subq_22.created_at__extract_dow
+ , subq_22.created_at__extract_doy
+ , subq_22.listing__ds__day
+ , subq_22.listing__ds__week
+ , subq_22.listing__ds__month
+ , subq_22.listing__ds__quarter
+ , subq_22.listing__ds__year
+ , subq_22.listing__ds__extract_year
+ , subq_22.listing__ds__extract_quarter
+ , subq_22.listing__ds__extract_month
+ , subq_22.listing__ds__extract_day
+ , subq_22.listing__ds__extract_dow
+ , subq_22.listing__ds__extract_doy
+ , subq_22.listing__created_at__day
+ , subq_22.listing__created_at__week
+ , subq_22.listing__created_at__month
+ , subq_22.listing__created_at__quarter
+ , subq_22.listing__created_at__year
+ , subq_22.listing__created_at__extract_year
+ , subq_22.listing__created_at__extract_quarter
+ , subq_22.listing__created_at__extract_month
+ , subq_22.listing__created_at__extract_day
+ , subq_22.listing__created_at__extract_dow
+ , subq_22.listing__created_at__extract_doy
+ , subq_22.ds__day AS metric_time__day
+ , subq_22.ds__week AS metric_time__week
+ , subq_22.ds__month AS metric_time__month
+ , subq_22.ds__quarter AS metric_time__quarter
+ , subq_22.ds__year AS metric_time__year
+ , subq_22.ds__extract_year AS metric_time__extract_year
+ , subq_22.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_22.ds__extract_month AS metric_time__extract_month
+ , subq_22.ds__extract_day AS metric_time__extract_day
+ , subq_22.ds__extract_dow AS metric_time__extract_dow
+ , subq_22.ds__extract_doy AS metric_time__extract_doy
+ , subq_22.listing
+ , subq_22.user
+ , subq_22.listing__user
+ , subq_22.country_latest
+ , subq_22.is_lux_latest
+ , subq_22.capacity_latest
+ , subq_22.listing__country_latest
+ , subq_22.listing__is_lux_latest
+ , subq_22.listing__capacity_latest
+ , subq_22.listings
+ , subq_22.largest_listing
+ , subq_22.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_22
+ ) subq_23
+ ) subq_24
+ ON
+ subq_21.listing = subq_24.listing
+ ) subq_25
+ WHERE ((listing IS NOT NULL) AND (booking__is_instant)) AND (listing__created_at__day >= '2020-01-02')
+ ) subq_26
+ ) subq_27
+ GROUP BY
+ subq_27.metric_time__day
+ ) subq_28
+ ) subq_29
+ ON
+ subq_15.metric_time__day = subq_29.metric_time__day
+ GROUP BY
+ COALESCE(subq_15.metric_time__day, subq_29.metric_time__day)
+ ) subq_30
+ ) subq_31
+ ON
+ DATE_TRUNC('week', subq_32.metric_time__day) = subq_31.metric_time__day
+ ) subq_35
+ ON
+ subq_5.metric_time__day = subq_35.metric_time__day
+ GROUP BY
+ COALESCE(subq_5.metric_time__day, subq_35.metric_time__day)
+) subq_36
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_to_grain_metric_with_tiered_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_to_grain_metric_with_tiered_filters__plan0_optimized.sql
new file mode 100644
index 000000000..e0578d38e
--- /dev/null
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_to_grain_metric_with_tiered_filters__plan0_optimized.sql
@@ -0,0 +1,183 @@
+test_name: test_nested_offset_to_grain_metric_with_tiered_filters
+test_filename: test_derived_metric_rendering.py
+docstring:
+ Tests that filters at different tiers are applied appropriately for derived metrics with offset to grain.
+sql_engine: DuckDB
+---
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , bookings_this_month_wtd - bookings AS bookings_offset_to_grain_twice_with_tiered_filters
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_42.metric_time__day, subq_72.metric_time__day) AS metric_time__day
+ , MAX(subq_42.bookings) AS bookings
+ , MAX(subq_72.bookings_this_month_wtd) AS bookings_this_month_wtd
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , DATE_TRUNC('month', ds) AS metric_time__month
+ , DATE_TRUNC('quarter', ds) AS metric_time__quarter
+ , listing_id AS listing
+ , is_instant AS booking__is_instant
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_28000
+ ) subq_38
+ WHERE (((listing IS NOT NULL) AND (metric_time__quarter >= '2020-01-01')) AND (metric_time__month >= '2020-01-01')) AND (booking__is_instant)
+ GROUP BY
+ metric_time__day
+ ) subq_42
+ FULL OUTER JOIN (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_69.metric_time__day AS metric_time__day
+ , subq_68.bookings_this_month_wtd AS bookings_this_month_wtd
+ FROM (
+ -- Filter Time Spine
+ SELECT
+ metric_time__day
+ FROM (
+ -- Time Spine
+ SELECT
+ ds AS metric_time__day
+ , DATE_TRUNC('month', ds) AS metric_time__month
+ , DATE_TRUNC('quarter', ds) AS metric_time__quarter
+ FROM ***************************.mf_time_spine subq_70
+ ) subq_71
+ WHERE (
+ metric_time__quarter >= '2020-01-01'
+ ) AND (
+ metric_time__month >= '2020-01-01'
+ )
+ ) subq_69
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , bookings - bookings_at_start_of_month AS bookings_this_month_wtd
+ FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_52.metric_time__day, subq_66.metric_time__day) AS metric_time__day
+ , MAX(subq_52.bookings) AS bookings
+ , MAX(subq_66.bookings_at_start_of_month) AS bookings_at_start_of_month
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day
+ , subq_44.booking__ds__year AS booking__ds__year
+ , subq_44.metric_time__day AS metric_time__day
+ , subq_44.listing AS listing
+ , subq_44.booking__is_instant AS booking__is_instant
+ , subq_44.bookings AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('year', ds) AS booking__ds__year
+ , DATE_TRUNC('day', ds) AS metric_time__day
+ , listing_id AS listing
+ , is_instant AS booking__is_instant
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_28000
+ ) subq_44
+ LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_28000
+ ON
+ subq_44.listing = listings_latest_src_28000.listing_id
+ ) subq_48
+ WHERE (((listing IS NOT NULL) AND (booking__is_instant)) AND (booking__ds__year >= '2019-01-01')) AND (listing__created_at__day >= '2020-01-02')
+ GROUP BY
+ metric_time__day
+ ) subq_52
+ FULL OUTER JOIN (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings_at_start_of_month
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day
+ , subq_58.metric_time__day AS metric_time__day
+ , subq_58.listing AS listing
+ , subq_58.booking__is_instant AS booking__is_instant
+ , subq_58.bookings AS bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_55.metric_time__day AS metric_time__day
+ , subq_54.listing AS listing
+ , subq_54.booking__is_instant AS booking__is_instant
+ , subq_54.bookings AS bookings
+ FROM (
+ -- Filter Time Spine
+ SELECT
+ metric_time__day
+ FROM (
+ -- Time Spine
+ SELECT
+ DATE_TRUNC('year', ds) AS booking__ds__year
+ , ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_56
+ ) subq_57
+ WHERE booking__ds__year >= '2019-01-01'
+ ) subq_55
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , listing_id AS listing
+ , is_instant AS booking__is_instant
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_28000
+ ) subq_54
+ ON
+ DATE_TRUNC('month', subq_55.metric_time__day) = subq_54.metric_time__day
+ ) subq_58
+ LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_28000
+ ON
+ subq_58.listing = listings_latest_src_28000.listing_id
+ ) subq_62
+ WHERE ((listing IS NOT NULL) AND (booking__is_instant)) AND (listing__created_at__day >= '2020-01-02')
+ GROUP BY
+ metric_time__day
+ ) subq_66
+ ON
+ subq_52.metric_time__day = subq_66.metric_time__day
+ GROUP BY
+ COALESCE(subq_52.metric_time__day, subq_66.metric_time__day)
+ ) subq_67
+ ) subq_68
+ ON
+ DATE_TRUNC('week', subq_69.metric_time__day) = subq_68.metric_time__day
+ ) subq_72
+ ON
+ subq_42.metric_time__day = subq_72.metric_time__day
+ GROUP BY
+ COALESCE(subq_42.metric_time__day, subq_72.metric_time__day)
+) subq_73
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_window_metric_with_tiered_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_window_metric_with_tiered_filters__plan0.sql
new file mode 100644
index 000000000..9e4b6d6f9
--- /dev/null
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_window_metric_with_tiered_filters__plan0.sql
@@ -0,0 +1,724 @@
+test_name: test_nested_offset_window_metric_with_tiered_filters
+test_filename: test_derived_metric_rendering.py
+docstring:
+ Tests that filters at different tiers are applied appropriately for derived metrics.
+
+ This includes filters at the input metric, metric, and query level. At each tier there are filters on both
+ metric_time / agg time and another dimension, which might have different behaviors.
+sql_engine: DuckDB
+---
+-- Compute Metrics via Expressions
+SELECT
+ subq_18.metric_time__day
+ , bookings_offset_once AS bookings_offset_twice_with_tiered_filters
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_15.metric_time__day AS metric_time__day
+ , subq_14.bookings_offset_once AS bookings_offset_once
+ FROM (
+ -- Filter Time Spine
+ SELECT
+ subq_17.metric_time__day
+ FROM (
+ -- Time Spine
+ SELECT
+ DATE_TRUNC('quarter', subq_16.ds) AS booking__ds__quarter
+ , subq_16.ds AS metric_time__day
+ , DATE_TRUNC('year', subq_16.ds) AS metric_time__year
+ FROM ***************************.mf_time_spine subq_16
+ ) subq_17
+ WHERE (
+ booking__ds__quarter >= '2020-01-01'
+ ) AND (
+ metric_time__year >= '2019-01-01'
+ )
+ ) subq_15
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_13.metric_time__day
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_12.metric_time__day
+ , subq_12.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_11.metric_time__day
+ , SUM(subq_11.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
+ SELECT
+ subq_10.metric_time__day
+ , subq_10.bookings
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_9.metric_time__day
+ , subq_9.metric_time__week
+ , subq_9.metric_time__month
+ , subq_9.metric_time__quarter
+ , subq_9.metric_time__year
+ , subq_9.metric_time__extract_year
+ , subq_9.metric_time__extract_quarter
+ , subq_9.metric_time__extract_month
+ , subq_9.metric_time__extract_day
+ , subq_9.metric_time__extract_dow
+ , subq_9.metric_time__extract_doy
+ , subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.ds_partitioned__day
+ , subq_9.ds_partitioned__week
+ , subq_9.ds_partitioned__month
+ , subq_9.ds_partitioned__quarter
+ , subq_9.ds_partitioned__year
+ , subq_9.ds_partitioned__extract_year
+ , subq_9.ds_partitioned__extract_quarter
+ , subq_9.ds_partitioned__extract_month
+ , subq_9.ds_partitioned__extract_day
+ , subq_9.ds_partitioned__extract_dow
+ , subq_9.ds_partitioned__extract_doy
+ , subq_9.paid_at__day
+ , subq_9.paid_at__week
+ , subq_9.paid_at__month
+ , subq_9.paid_at__quarter
+ , subq_9.paid_at__year
+ , subq_9.paid_at__extract_year
+ , subq_9.paid_at__extract_quarter
+ , subq_9.paid_at__extract_month
+ , subq_9.paid_at__extract_day
+ , subq_9.paid_at__extract_dow
+ , subq_9.paid_at__extract_doy
+ , subq_9.booking__ds__day
+ , subq_9.booking__ds__week
+ , subq_9.booking__ds__month
+ , subq_9.booking__ds__quarter
+ , subq_9.booking__ds__year
+ , subq_9.booking__ds__extract_year
+ , subq_9.booking__ds__extract_quarter
+ , subq_9.booking__ds__extract_month
+ , subq_9.booking__ds__extract_day
+ , subq_9.booking__ds__extract_dow
+ , subq_9.booking__ds__extract_doy
+ , subq_9.booking__ds_partitioned__day
+ , subq_9.booking__ds_partitioned__week
+ , subq_9.booking__ds_partitioned__month
+ , subq_9.booking__ds_partitioned__quarter
+ , subq_9.booking__ds_partitioned__year
+ , subq_9.booking__ds_partitioned__extract_year
+ , subq_9.booking__ds_partitioned__extract_quarter
+ , subq_9.booking__ds_partitioned__extract_month
+ , subq_9.booking__ds_partitioned__extract_day
+ , subq_9.booking__ds_partitioned__extract_dow
+ , subq_9.booking__ds_partitioned__extract_doy
+ , subq_9.booking__paid_at__day
+ , subq_9.booking__paid_at__week
+ , subq_9.booking__paid_at__month
+ , subq_9.booking__paid_at__quarter
+ , subq_9.booking__paid_at__year
+ , subq_9.booking__paid_at__extract_year
+ , subq_9.booking__paid_at__extract_quarter
+ , subq_9.booking__paid_at__extract_month
+ , subq_9.booking__paid_at__extract_day
+ , subq_9.booking__paid_at__extract_dow
+ , subq_9.booking__paid_at__extract_doy
+ , subq_9.listing__created_at__day
+ , subq_9.listing
+ , subq_9.guest
+ , subq_9.host
+ , subq_9.booking__listing
+ , subq_9.booking__guest
+ , subq_9.booking__host
+ , subq_9.is_instant
+ , subq_9.booking__is_instant
+ , subq_9.bookings
+ , subq_9.instant_bookings
+ , subq_9.booking_value
+ , subq_9.max_booking_value
+ , subq_9.min_booking_value
+ , subq_9.bookers
+ , subq_9.average_booking_value
+ , subq_9.referred_bookings
+ , subq_9.median_booking_value
+ , subq_9.booking_value_p99
+ , subq_9.discrete_booking_value_p99
+ , subq_9.approximate_continuous_booking_value_p99
+ , subq_9.approximate_discrete_booking_value_p99
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_8.created_at__day AS listing__created_at__day
+ , subq_5.metric_time__day AS metric_time__day
+ , subq_5.metric_time__week AS metric_time__week
+ , subq_5.metric_time__month AS metric_time__month
+ , subq_5.metric_time__quarter AS metric_time__quarter
+ , subq_5.metric_time__year AS metric_time__year
+ , subq_5.metric_time__extract_year AS metric_time__extract_year
+ , subq_5.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_5.metric_time__extract_month AS metric_time__extract_month
+ , subq_5.metric_time__extract_day AS metric_time__extract_day
+ , subq_5.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_5.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_5.ds__day AS ds__day
+ , subq_5.ds__week AS ds__week
+ , subq_5.ds__month AS ds__month
+ , subq_5.ds__quarter AS ds__quarter
+ , subq_5.ds__year AS ds__year
+ , subq_5.ds__extract_year AS ds__extract_year
+ , subq_5.ds__extract_quarter AS ds__extract_quarter
+ , subq_5.ds__extract_month AS ds__extract_month
+ , subq_5.ds__extract_day AS ds__extract_day
+ , subq_5.ds__extract_dow AS ds__extract_dow
+ , subq_5.ds__extract_doy AS ds__extract_doy
+ , subq_5.ds_partitioned__day AS ds_partitioned__day
+ , subq_5.ds_partitioned__week AS ds_partitioned__week
+ , subq_5.ds_partitioned__month AS ds_partitioned__month
+ , subq_5.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_5.ds_partitioned__year AS ds_partitioned__year
+ , subq_5.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_5.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_5.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_5.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_5.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_5.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_5.paid_at__day AS paid_at__day
+ , subq_5.paid_at__week AS paid_at__week
+ , subq_5.paid_at__month AS paid_at__month
+ , subq_5.paid_at__quarter AS paid_at__quarter
+ , subq_5.paid_at__year AS paid_at__year
+ , subq_5.paid_at__extract_year AS paid_at__extract_year
+ , subq_5.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_5.paid_at__extract_month AS paid_at__extract_month
+ , subq_5.paid_at__extract_day AS paid_at__extract_day
+ , subq_5.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_5.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_5.booking__ds__day AS booking__ds__day
+ , subq_5.booking__ds__week AS booking__ds__week
+ , subq_5.booking__ds__month AS booking__ds__month
+ , subq_5.booking__ds__quarter AS booking__ds__quarter
+ , subq_5.booking__ds__year AS booking__ds__year
+ , subq_5.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_5.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_5.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_5.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_5.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_5.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_5.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_5.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_5.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_5.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_5.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_5.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_5.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_5.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_5.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_5.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_5.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_5.booking__paid_at__day AS booking__paid_at__day
+ , subq_5.booking__paid_at__week AS booking__paid_at__week
+ , subq_5.booking__paid_at__month AS booking__paid_at__month
+ , subq_5.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_5.booking__paid_at__year AS booking__paid_at__year
+ , subq_5.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_5.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_5.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_5.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_5.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_5.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_5.listing AS listing
+ , subq_5.guest AS guest
+ , subq_5.host AS host
+ , subq_5.booking__listing AS booking__listing
+ , subq_5.booking__guest AS booking__guest
+ , subq_5.booking__host AS booking__host
+ , subq_5.is_instant AS is_instant
+ , subq_5.booking__is_instant AS booking__is_instant
+ , subq_5.bookings AS bookings
+ , subq_5.instant_bookings AS instant_bookings
+ , subq_5.booking_value AS booking_value
+ , subq_5.max_booking_value AS max_booking_value
+ , subq_5.min_booking_value AS min_booking_value
+ , subq_5.bookers AS bookers
+ , subq_5.average_booking_value AS average_booking_value
+ , subq_5.referred_bookings AS referred_bookings
+ , subq_5.median_booking_value AS median_booking_value
+ , subq_5.booking_value_p99 AS booking_value_p99
+ , subq_5.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_5.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_5.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week
+ , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month
+ , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter
+ , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year
+ , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year
+ , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter
+ , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month
+ , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day
+ , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow
+ , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy
+ , subq_1.ds__day AS ds__day
+ , subq_1.ds__week AS ds__week
+ , subq_1.ds__month AS ds__month
+ , subq_1.ds__quarter AS ds__quarter
+ , subq_1.ds__year AS ds__year
+ , subq_1.ds__extract_year AS ds__extract_year
+ , subq_1.ds__extract_quarter AS ds__extract_quarter
+ , subq_1.ds__extract_month AS ds__extract_month
+ , subq_1.ds__extract_day AS ds__extract_day
+ , subq_1.ds__extract_dow AS ds__extract_dow
+ , subq_1.ds__extract_doy AS ds__extract_doy
+ , subq_1.ds_partitioned__day AS ds_partitioned__day
+ , subq_1.ds_partitioned__week AS ds_partitioned__week
+ , subq_1.ds_partitioned__month AS ds_partitioned__month
+ , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_1.ds_partitioned__year AS ds_partitioned__year
+ , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_1.paid_at__day AS paid_at__day
+ , subq_1.paid_at__week AS paid_at__week
+ , subq_1.paid_at__month AS paid_at__month
+ , subq_1.paid_at__quarter AS paid_at__quarter
+ , subq_1.paid_at__year AS paid_at__year
+ , subq_1.paid_at__extract_year AS paid_at__extract_year
+ , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_1.paid_at__extract_month AS paid_at__extract_month
+ , subq_1.paid_at__extract_day AS paid_at__extract_day
+ , subq_1.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_1.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_1.booking__ds__day AS booking__ds__day
+ , subq_1.booking__ds__week AS booking__ds__week
+ , subq_1.booking__ds__month AS booking__ds__month
+ , subq_1.booking__ds__quarter AS booking__ds__quarter
+ , subq_1.booking__ds__year AS booking__ds__year
+ , subq_1.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_1.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_1.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_1.booking__paid_at__day AS booking__paid_at__day
+ , subq_1.booking__paid_at__week AS booking__paid_at__week
+ , subq_1.booking__paid_at__month AS booking__paid_at__month
+ , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_1.booking__paid_at__year AS booking__paid_at__year
+ , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_1.listing AS listing
+ , subq_1.guest AS guest
+ , subq_1.host AS host
+ , subq_1.booking__listing AS booking__listing
+ , subq_1.booking__guest AS booking__guest
+ , subq_1.booking__host AS booking__host
+ , subq_1.is_instant AS is_instant
+ , subq_1.booking__is_instant AS booking__is_instant
+ , subq_1.bookings AS bookings
+ , subq_1.instant_bookings AS instant_bookings
+ , subq_1.booking_value AS booking_value
+ , subq_1.max_booking_value AS max_booking_value
+ , subq_1.min_booking_value AS min_booking_value
+ , subq_1.bookers AS bookers
+ , subq_1.average_booking_value AS average_booking_value
+ , subq_1.referred_bookings AS referred_bookings
+ , subq_1.median_booking_value AS median_booking_value
+ , subq_1.booking_value_p99 AS booking_value_p99
+ , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Filter Time Spine
+ SELECT
+ subq_4.metric_time__day
+ FROM (
+ -- Time Spine
+ SELECT
+ subq_3.ds AS metric_time__day
+ , DATE_TRUNC('month', subq_3.ds) AS metric_time__month
+ FROM ***************************.mf_time_spine subq_3
+ ) subq_4
+ WHERE metric_time__month >= '2019-12-01'
+ ) subq_2
+ INNER JOIN (
+ -- 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
+ ON
+ subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day
+ ) subq_5
+ LEFT OUTER JOIN (
+ -- Pass Only Elements: ['created_at__day', 'listing']
+ SELECT
+ subq_7.created_at__day
+ , subq_7.listing
+ 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
+ WHERE ((listing__created_at__day = '2020-01-01') AND (listing IS NOT NULL)) AND (booking__is_instant)
+ ) subq_10
+ ) subq_11
+ GROUP BY
+ subq_11.metric_time__day
+ ) subq_12
+ ) subq_13
+ ) subq_14
+ ON
+ subq_15.metric_time__day - INTERVAL 1 month = subq_14.metric_time__day
+) subq_18
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_window_metric_with_tiered_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_window_metric_with_tiered_filters__plan0_optimized.sql
new file mode 100644
index 000000000..66660a539
--- /dev/null
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offset_window_metric_with_tiered_filters__plan0_optimized.sql
@@ -0,0 +1,103 @@
+test_name: test_nested_offset_window_metric_with_tiered_filters
+test_filename: test_derived_metric_rendering.py
+docstring:
+ Tests that filters at different tiers are applied appropriately for derived metrics.
+
+ This includes filters at the input metric, metric, and query level. At each tier there are filters on both
+ metric_time / agg time and another dimension, which might have different behaviors.
+sql_engine: DuckDB
+---
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , bookings_offset_once AS bookings_offset_twice_with_tiered_filters
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_34.metric_time__day AS metric_time__day
+ , subq_33.bookings_offset_once AS bookings_offset_once
+ FROM (
+ -- Filter Time Spine
+ SELECT
+ metric_time__day
+ FROM (
+ -- Time Spine
+ SELECT
+ DATE_TRUNC('quarter', ds) AS booking__ds__quarter
+ , ds AS metric_time__day
+ , DATE_TRUNC('year', ds) AS metric_time__year
+ FROM ***************************.mf_time_spine subq_35
+ ) subq_36
+ WHERE (
+ booking__ds__quarter >= '2020-01-01'
+ ) AND (
+ metric_time__year >= '2019-01-01'
+ )
+ ) subq_34
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day
+ , subq_24.metric_time__day AS metric_time__day
+ , subq_24.listing AS listing
+ , subq_24.booking__is_instant AS booking__is_instant
+ , subq_24.bookings AS bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_21.metric_time__day AS metric_time__day
+ , subq_20.listing AS listing
+ , subq_20.booking__is_instant AS booking__is_instant
+ , subq_20.bookings AS bookings
+ FROM (
+ -- Filter Time Spine
+ SELECT
+ metric_time__day
+ FROM (
+ -- Time Spine
+ SELECT
+ ds AS metric_time__day
+ , DATE_TRUNC('month', ds) AS metric_time__month
+ FROM ***************************.mf_time_spine subq_22
+ ) subq_23
+ WHERE metric_time__month >= '2019-12-01'
+ ) subq_21
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , listing_id AS listing
+ , is_instant AS booking__is_instant
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_28000
+ ) subq_20
+ ON
+ subq_21.metric_time__day - INTERVAL 5 day = subq_20.metric_time__day
+ ) subq_24
+ LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_28000
+ ON
+ subq_24.listing = listings_latest_src_28000.listing_id
+ ) subq_28
+ WHERE ((listing__created_at__day = '2020-01-01') AND (listing IS NOT NULL)) AND (booking__is_instant)
+ GROUP BY
+ metric_time__day
+ ) subq_32
+ ) subq_33
+ ON
+ subq_34.metric_time__day - INTERVAL 1 month = subq_33.metric_time__day
+) subq_37
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql
index b104ae2cb..3d0c4561b 100644
--- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql
@@ -7,354 +7,353 @@ SELECT
subq_12.metric_time__day
, 2 * bookings_offset_once AS bookings_offset_twice
FROM (
- -- Constrain Output with WHERE
+ -- Join to Time Spine Dataset
SELECT
- subq_11.metric_time__day
- , subq_11.bookings_offset_once
+ subq_9.metric_time__day AS metric_time__day
+ , subq_8.bookings_offset_once AS bookings_offset_once
FROM (
- -- Join to Time Spine Dataset
+ -- Filter Time Spine
SELECT
- subq_9.metric_time__day AS metric_time__day
- , subq_8.bookings_offset_once AS bookings_offset_once
+ subq_11.metric_time__day
FROM (
-- Time Spine
SELECT
subq_10.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_10
- ) subq_9
- INNER JOIN (
+ ) subq_11
+ WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13'
+ ) subq_9
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_7.metric_time__day
+ , 2 * bookings AS bookings_offset_once
+ FROM (
-- Compute Metrics via Expressions
SELECT
- subq_7.metric_time__day
- , 2 * bookings AS bookings_offset_once
+ subq_6.metric_time__day
+ , subq_6.bookings
FROM (
- -- Compute Metrics via Expressions
+ -- Aggregate Measures
SELECT
- subq_6.metric_time__day
- , subq_6.bookings
+ subq_5.metric_time__day
+ , SUM(subq_5.bookings) AS bookings
FROM (
- -- Aggregate Measures
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
SELECT
- subq_5.metric_time__day
- , SUM(subq_5.bookings) AS bookings
+ subq_4.metric_time__day
+ , subq_4.bookings
FROM (
- -- Pass Only Elements: ['bookings', 'metric_time__day']
+ -- Join to Time Spine Dataset
SELECT
- subq_4.metric_time__day
- , subq_4.bookings
+ subq_2.metric_time__day AS metric_time__day
+ , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week
+ , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month
+ , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter
+ , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year
+ , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year
+ , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter
+ , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month
+ , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day
+ , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow
+ , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy
+ , subq_1.ds__day AS ds__day
+ , subq_1.ds__week AS ds__week
+ , subq_1.ds__month AS ds__month
+ , subq_1.ds__quarter AS ds__quarter
+ , subq_1.ds__year AS ds__year
+ , subq_1.ds__extract_year AS ds__extract_year
+ , subq_1.ds__extract_quarter AS ds__extract_quarter
+ , subq_1.ds__extract_month AS ds__extract_month
+ , subq_1.ds__extract_day AS ds__extract_day
+ , subq_1.ds__extract_dow AS ds__extract_dow
+ , subq_1.ds__extract_doy AS ds__extract_doy
+ , subq_1.ds_partitioned__day AS ds_partitioned__day
+ , subq_1.ds_partitioned__week AS ds_partitioned__week
+ , subq_1.ds_partitioned__month AS ds_partitioned__month
+ , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_1.ds_partitioned__year AS ds_partitioned__year
+ , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_1.paid_at__day AS paid_at__day
+ , subq_1.paid_at__week AS paid_at__week
+ , subq_1.paid_at__month AS paid_at__month
+ , subq_1.paid_at__quarter AS paid_at__quarter
+ , subq_1.paid_at__year AS paid_at__year
+ , subq_1.paid_at__extract_year AS paid_at__extract_year
+ , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_1.paid_at__extract_month AS paid_at__extract_month
+ , subq_1.paid_at__extract_day AS paid_at__extract_day
+ , subq_1.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_1.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_1.booking__ds__day AS booking__ds__day
+ , subq_1.booking__ds__week AS booking__ds__week
+ , subq_1.booking__ds__month AS booking__ds__month
+ , subq_1.booking__ds__quarter AS booking__ds__quarter
+ , subq_1.booking__ds__year AS booking__ds__year
+ , subq_1.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_1.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_1.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_1.booking__paid_at__day AS booking__paid_at__day
+ , subq_1.booking__paid_at__week AS booking__paid_at__week
+ , subq_1.booking__paid_at__month AS booking__paid_at__month
+ , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_1.booking__paid_at__year AS booking__paid_at__year
+ , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_1.listing AS listing
+ , subq_1.guest AS guest
+ , subq_1.host AS host
+ , subq_1.booking__listing AS booking__listing
+ , subq_1.booking__guest AS booking__guest
+ , subq_1.booking__host AS booking__host
+ , subq_1.is_instant AS is_instant
+ , subq_1.booking__is_instant AS booking__is_instant
+ , subq_1.bookings AS bookings
+ , subq_1.instant_bookings AS instant_bookings
+ , subq_1.booking_value AS booking_value
+ , subq_1.max_booking_value AS max_booking_value
+ , subq_1.min_booking_value AS min_booking_value
+ , subq_1.bookers AS bookers
+ , subq_1.average_booking_value AS average_booking_value
+ , subq_1.referred_bookings AS referred_bookings
+ , subq_1.median_booking_value AS median_booking_value
+ , subq_1.booking_value_p99 AS booking_value_p99
+ , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
FROM (
- -- Join to Time Spine Dataset
+ -- Time Spine
SELECT
- subq_2.metric_time__day AS metric_time__day
- , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week
- , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month
- , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter
- , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year
- , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year
- , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter
- , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month
- , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day
- , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow
- , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy
- , subq_1.ds__day AS ds__day
- , subq_1.ds__week AS ds__week
- , subq_1.ds__month AS ds__month
- , subq_1.ds__quarter AS ds__quarter
- , subq_1.ds__year AS ds__year
- , subq_1.ds__extract_year AS ds__extract_year
- , subq_1.ds__extract_quarter AS ds__extract_quarter
- , subq_1.ds__extract_month AS ds__extract_month
- , subq_1.ds__extract_day AS ds__extract_day
- , subq_1.ds__extract_dow AS ds__extract_dow
- , subq_1.ds__extract_doy AS ds__extract_doy
- , subq_1.ds_partitioned__day AS ds_partitioned__day
- , subq_1.ds_partitioned__week AS ds_partitioned__week
- , subq_1.ds_partitioned__month AS ds_partitioned__month
- , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter
- , subq_1.ds_partitioned__year AS ds_partitioned__year
- , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year
- , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
- , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month
- , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day
- , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
- , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
- , subq_1.paid_at__day AS paid_at__day
- , subq_1.paid_at__week AS paid_at__week
- , subq_1.paid_at__month AS paid_at__month
- , subq_1.paid_at__quarter AS paid_at__quarter
- , subq_1.paid_at__year AS paid_at__year
- , subq_1.paid_at__extract_year AS paid_at__extract_year
- , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter
- , subq_1.paid_at__extract_month AS paid_at__extract_month
- , subq_1.paid_at__extract_day AS paid_at__extract_day
- , subq_1.paid_at__extract_dow AS paid_at__extract_dow
- , subq_1.paid_at__extract_doy AS paid_at__extract_doy
- , subq_1.booking__ds__day AS booking__ds__day
- , subq_1.booking__ds__week AS booking__ds__week
- , subq_1.booking__ds__month AS booking__ds__month
- , subq_1.booking__ds__quarter AS booking__ds__quarter
- , subq_1.booking__ds__year AS booking__ds__year
- , subq_1.booking__ds__extract_year AS booking__ds__extract_year
- , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter
- , subq_1.booking__ds__extract_month AS booking__ds__extract_month
- , subq_1.booking__ds__extract_day AS booking__ds__extract_day
- , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow
- , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy
- , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day
- , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week
- , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month
- , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
- , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year
- , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
- , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
- , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
- , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
- , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
- , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
- , subq_1.booking__paid_at__day AS booking__paid_at__day
- , subq_1.booking__paid_at__week AS booking__paid_at__week
- , subq_1.booking__paid_at__month AS booking__paid_at__month
- , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter
- , subq_1.booking__paid_at__year AS booking__paid_at__year
- , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year
- , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
- , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month
- , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day
- , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
- , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
- , subq_1.listing AS listing
- , subq_1.guest AS guest
- , subq_1.host AS host
- , subq_1.booking__listing AS booking__listing
- , subq_1.booking__guest AS booking__guest
- , subq_1.booking__host AS booking__host
- , subq_1.is_instant AS is_instant
- , subq_1.booking__is_instant AS booking__is_instant
- , subq_1.bookings AS bookings
- , subq_1.instant_bookings AS instant_bookings
- , subq_1.booking_value AS booking_value
- , subq_1.max_booking_value AS max_booking_value
- , subq_1.min_booking_value AS min_booking_value
- , subq_1.bookers AS bookers
- , subq_1.average_booking_value AS average_booking_value
- , subq_1.referred_bookings AS referred_bookings
- , subq_1.median_booking_value AS median_booking_value
- , subq_1.booking_value_p99 AS booking_value_p99
- , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99
- , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
- , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ subq_3.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_3
+ ) subq_2
+ INNER JOIN (
+ -- 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 (
- -- Time Spine
- SELECT
- subq_3.ds AS metric_time__day
- FROM ***************************.mf_time_spine subq_3
- ) subq_2
- INNER JOIN (
- -- Metric Time Dimension 'ds'
+ -- Read Elements From Semantic Model 'bookings_source'
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
- ON
- subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day
- ) subq_4
- ) subq_5
- GROUP BY
- subq_5.metric_time__day
- ) subq_6
- ) subq_7
- ) subq_8
- ON
- subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day
- ) subq_11
- WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13'
+ 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
+ ON
+ subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day
+ ) subq_4
+ ) subq_5
+ GROUP BY
+ subq_5.metric_time__day
+ ) subq_6
+ ) subq_7
+ ) subq_8
+ ON
+ subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day
) subq_12
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql
index 5d979eb0c..ac9ccbd9b 100644
--- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0_optimized.sql
@@ -7,46 +7,50 @@ SELECT
metric_time__day
, 2 * bookings_offset_once AS bookings_offset_twice
FROM (
- -- Constrain Output with WHERE
+ -- Join to Time Spine Dataset
SELECT
- metric_time__day
- , bookings_offset_once
+ subq_22.metric_time__day AS metric_time__day
+ , subq_21.bookings_offset_once AS bookings_offset_once
FROM (
- -- Join to Time Spine Dataset
+ -- Filter Time Spine
SELECT
- subq_23.ds AS metric_time__day
- , subq_21.bookings_offset_once AS bookings_offset_once
- FROM ***************************.mf_time_spine subq_23
- INNER JOIN (
+ metric_time__day
+ FROM (
+ -- Time Spine
+ SELECT
+ ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_23
+ ) subq_24
+ WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13'
+ ) subq_22
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements: ['bookings', 'metric_time__day']
+ -- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
- metric_time__day
- , 2 * bookings AS bookings_offset_once
- FROM (
- -- Join to Time Spine Dataset
- -- Pass Only Elements: ['bookings', 'metric_time__day']
- -- Aggregate Measures
- -- Compute Metrics via Expressions
+ subq_16.ds AS metric_time__day
+ , SUM(subq_14.bookings) AS bookings
+ FROM ***************************.mf_time_spine subq_16
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
SELECT
- subq_16.ds AS metric_time__day
- , SUM(subq_14.bookings) AS bookings
- FROM ***************************.mf_time_spine subq_16
- INNER JOIN (
- -- Read Elements From Semantic Model 'bookings_source'
- -- Metric Time Dimension 'ds'
- SELECT
- DATE_TRUNC('day', ds) AS metric_time__day
- , 1 AS bookings
- FROM ***************************.fct_bookings bookings_source_src_28000
- ) subq_14
- ON
- subq_16.ds - INTERVAL 5 day = subq_14.metric_time__day
- GROUP BY
- subq_16.ds
- ) subq_20
- ) subq_21
- ON
- subq_23.ds - INTERVAL 2 day = subq_21.metric_time__day
- ) subq_24
- WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13'
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_28000
+ ) subq_14
+ ON
+ subq_16.ds - INTERVAL 5 day = subq_14.metric_time__day
+ GROUP BY
+ subq_16.ds
+ ) subq_20
+ ) subq_21
+ ON
+ subq_22.metric_time__day - INTERVAL 2 day = subq_21.metric_time__day
) subq_25
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql
index 72b5a8eff..a335876ee 100644
--- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql
@@ -24,413 +24,316 @@ FROM (
subq_5.metric_time__month
, subq_5.bookings
FROM (
- -- Constrain Output with WHERE
+ -- Join to Time Spine Dataset
SELECT
- subq_4.metric_time__day
- , subq_4.metric_time__week
- , subq_4.metric_time__month
- , subq_4.metric_time__quarter
- , subq_4.metric_time__year
- , subq_4.metric_time__extract_year
- , subq_4.metric_time__extract_quarter
- , subq_4.metric_time__extract_month
- , subq_4.metric_time__extract_day
- , subq_4.metric_time__extract_dow
- , subq_4.metric_time__extract_doy
- , subq_4.ds__day
- , subq_4.ds__week
- , subq_4.ds__month
- , subq_4.ds__quarter
- , subq_4.ds__year
- , subq_4.ds__extract_year
- , subq_4.ds__extract_quarter
- , subq_4.ds__extract_month
- , subq_4.ds__extract_day
- , subq_4.ds__extract_dow
- , subq_4.ds__extract_doy
- , subq_4.ds_partitioned__day
- , subq_4.ds_partitioned__week
- , subq_4.ds_partitioned__month
- , subq_4.ds_partitioned__quarter
- , subq_4.ds_partitioned__year
- , subq_4.ds_partitioned__extract_year
- , subq_4.ds_partitioned__extract_quarter
- , subq_4.ds_partitioned__extract_month
- , subq_4.ds_partitioned__extract_day
- , subq_4.ds_partitioned__extract_dow
- , subq_4.ds_partitioned__extract_doy
- , subq_4.paid_at__day
- , subq_4.paid_at__week
- , subq_4.paid_at__month
- , subq_4.paid_at__quarter
- , subq_4.paid_at__year
- , subq_4.paid_at__extract_year
- , subq_4.paid_at__extract_quarter
- , subq_4.paid_at__extract_month
- , subq_4.paid_at__extract_day
- , subq_4.paid_at__extract_dow
- , subq_4.paid_at__extract_doy
- , subq_4.booking__ds__day
- , subq_4.booking__ds__week
- , subq_4.booking__ds__month
- , subq_4.booking__ds__quarter
- , subq_4.booking__ds__year
- , subq_4.booking__ds__extract_year
- , subq_4.booking__ds__extract_quarter
- , subq_4.booking__ds__extract_month
- , subq_4.booking__ds__extract_day
- , subq_4.booking__ds__extract_dow
- , subq_4.booking__ds__extract_doy
- , subq_4.booking__ds_partitioned__day
- , subq_4.booking__ds_partitioned__week
- , subq_4.booking__ds_partitioned__month
- , subq_4.booking__ds_partitioned__quarter
- , subq_4.booking__ds_partitioned__year
- , subq_4.booking__ds_partitioned__extract_year
- , subq_4.booking__ds_partitioned__extract_quarter
- , subq_4.booking__ds_partitioned__extract_month
- , subq_4.booking__ds_partitioned__extract_day
- , subq_4.booking__ds_partitioned__extract_dow
- , subq_4.booking__ds_partitioned__extract_doy
- , subq_4.booking__paid_at__day
- , subq_4.booking__paid_at__week
- , subq_4.booking__paid_at__month
- , subq_4.booking__paid_at__quarter
- , subq_4.booking__paid_at__year
- , subq_4.booking__paid_at__extract_year
- , subq_4.booking__paid_at__extract_quarter
- , subq_4.booking__paid_at__extract_month
- , subq_4.booking__paid_at__extract_day
- , subq_4.booking__paid_at__extract_dow
- , subq_4.booking__paid_at__extract_doy
- , subq_4.listing
- , subq_4.guest
- , subq_4.host
- , subq_4.booking__listing
- , subq_4.booking__guest
- , subq_4.booking__host
- , subq_4.is_instant
- , subq_4.booking__is_instant
- , subq_4.bookings
- , subq_4.instant_bookings
- , subq_4.booking_value
- , subq_4.max_booking_value
- , subq_4.min_booking_value
- , subq_4.bookers
- , subq_4.average_booking_value
- , subq_4.referred_bookings
- , subq_4.median_booking_value
- , subq_4.booking_value_p99
- , subq_4.discrete_booking_value_p99
- , subq_4.approximate_continuous_booking_value_p99
- , subq_4.approximate_discrete_booking_value_p99
+ subq_2.metric_time__day AS metric_time__day
+ , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week
+ , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month
+ , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter
+ , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year
+ , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year
+ , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter
+ , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month
+ , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day
+ , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow
+ , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy
+ , subq_1.ds__day AS ds__day
+ , subq_1.ds__week AS ds__week
+ , subq_1.ds__month AS ds__month
+ , subq_1.ds__quarter AS ds__quarter
+ , subq_1.ds__year AS ds__year
+ , subq_1.ds__extract_year AS ds__extract_year
+ , subq_1.ds__extract_quarter AS ds__extract_quarter
+ , subq_1.ds__extract_month AS ds__extract_month
+ , subq_1.ds__extract_day AS ds__extract_day
+ , subq_1.ds__extract_dow AS ds__extract_dow
+ , subq_1.ds__extract_doy AS ds__extract_doy
+ , subq_1.ds_partitioned__day AS ds_partitioned__day
+ , subq_1.ds_partitioned__week AS ds_partitioned__week
+ , subq_1.ds_partitioned__month AS ds_partitioned__month
+ , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_1.ds_partitioned__year AS ds_partitioned__year
+ , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_1.paid_at__day AS paid_at__day
+ , subq_1.paid_at__week AS paid_at__week
+ , subq_1.paid_at__month AS paid_at__month
+ , subq_1.paid_at__quarter AS paid_at__quarter
+ , subq_1.paid_at__year AS paid_at__year
+ , subq_1.paid_at__extract_year AS paid_at__extract_year
+ , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_1.paid_at__extract_month AS paid_at__extract_month
+ , subq_1.paid_at__extract_day AS paid_at__extract_day
+ , subq_1.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_1.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_1.booking__ds__day AS booking__ds__day
+ , subq_1.booking__ds__week AS booking__ds__week
+ , subq_1.booking__ds__month AS booking__ds__month
+ , subq_1.booking__ds__quarter AS booking__ds__quarter
+ , subq_1.booking__ds__year AS booking__ds__year
+ , subq_1.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_1.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_1.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_1.booking__paid_at__day AS booking__paid_at__day
+ , subq_1.booking__paid_at__week AS booking__paid_at__week
+ , subq_1.booking__paid_at__month AS booking__paid_at__month
+ , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_1.booking__paid_at__year AS booking__paid_at__year
+ , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_1.listing AS listing
+ , subq_1.guest AS guest
+ , subq_1.host AS host
+ , subq_1.booking__listing AS booking__listing
+ , subq_1.booking__guest AS booking__guest
+ , subq_1.booking__host AS booking__host
+ , subq_1.is_instant AS is_instant
+ , subq_1.booking__is_instant AS booking__is_instant
+ , subq_1.bookings AS bookings
+ , subq_1.instant_bookings AS instant_bookings
+ , subq_1.booking_value AS booking_value
+ , subq_1.max_booking_value AS max_booking_value
+ , subq_1.min_booking_value AS min_booking_value
+ , subq_1.bookers AS bookers
+ , subq_1.average_booking_value AS average_booking_value
+ , subq_1.referred_bookings AS referred_bookings
+ , subq_1.median_booking_value AS median_booking_value
+ , subq_1.booking_value_p99 AS booking_value_p99
+ , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
FROM (
- -- Join to Time Spine Dataset
+ -- Filter Time Spine
SELECT
- subq_2.metric_time__day AS metric_time__day
- , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week
- , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month
- , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter
- , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year
- , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year
- , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter
- , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month
- , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day
- , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow
- , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy
- , subq_1.ds__day AS ds__day
- , subq_1.ds__week AS ds__week
- , subq_1.ds__month AS ds__month
- , subq_1.ds__quarter AS ds__quarter
- , subq_1.ds__year AS ds__year
- , subq_1.ds__extract_year AS ds__extract_year
- , subq_1.ds__extract_quarter AS ds__extract_quarter
- , subq_1.ds__extract_month AS ds__extract_month
- , subq_1.ds__extract_day AS ds__extract_day
- , subq_1.ds__extract_dow AS ds__extract_dow
- , subq_1.ds__extract_doy AS ds__extract_doy
- , subq_1.ds_partitioned__day AS ds_partitioned__day
- , subq_1.ds_partitioned__week AS ds_partitioned__week
- , subq_1.ds_partitioned__month AS ds_partitioned__month
- , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter
- , subq_1.ds_partitioned__year AS ds_partitioned__year
- , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year
- , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
- , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month
- , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day
- , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
- , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
- , subq_1.paid_at__day AS paid_at__day
- , subq_1.paid_at__week AS paid_at__week
- , subq_1.paid_at__month AS paid_at__month
- , subq_1.paid_at__quarter AS paid_at__quarter
- , subq_1.paid_at__year AS paid_at__year
- , subq_1.paid_at__extract_year AS paid_at__extract_year
- , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter
- , subq_1.paid_at__extract_month AS paid_at__extract_month
- , subq_1.paid_at__extract_day AS paid_at__extract_day
- , subq_1.paid_at__extract_dow AS paid_at__extract_dow
- , subq_1.paid_at__extract_doy AS paid_at__extract_doy
- , subq_1.booking__ds__day AS booking__ds__day
- , subq_1.booking__ds__week AS booking__ds__week
- , subq_1.booking__ds__month AS booking__ds__month
- , subq_1.booking__ds__quarter AS booking__ds__quarter
- , subq_1.booking__ds__year AS booking__ds__year
- , subq_1.booking__ds__extract_year AS booking__ds__extract_year
- , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter
- , subq_1.booking__ds__extract_month AS booking__ds__extract_month
- , subq_1.booking__ds__extract_day AS booking__ds__extract_day
- , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow
- , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy
- , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day
- , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week
- , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month
- , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
- , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year
- , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
- , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
- , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
- , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
- , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
- , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
- , subq_1.booking__paid_at__day AS booking__paid_at__day
- , subq_1.booking__paid_at__week AS booking__paid_at__week
- , subq_1.booking__paid_at__month AS booking__paid_at__month
- , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter
- , subq_1.booking__paid_at__year AS booking__paid_at__year
- , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year
- , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
- , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month
- , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day
- , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
- , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
- , subq_1.listing AS listing
- , subq_1.guest AS guest
- , subq_1.host AS host
- , subq_1.booking__listing AS booking__listing
- , subq_1.booking__guest AS booking__guest
- , subq_1.booking__host AS booking__host
- , subq_1.is_instant AS is_instant
- , subq_1.booking__is_instant AS booking__is_instant
- , subq_1.bookings AS bookings
- , subq_1.instant_bookings AS instant_bookings
- , subq_1.booking_value AS booking_value
- , subq_1.max_booking_value AS max_booking_value
- , subq_1.min_booking_value AS min_booking_value
- , subq_1.bookers AS bookers
- , subq_1.average_booking_value AS average_booking_value
- , subq_1.referred_bookings AS referred_bookings
- , subq_1.median_booking_value AS median_booking_value
- , subq_1.booking_value_p99 AS booking_value_p99
- , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99
- , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
- , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ subq_4.metric_time__day
FROM (
-- Time Spine
SELECT
subq_3.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_3
- ) subq_2
- INNER JOIN (
- -- Metric Time Dimension 'ds'
+ ) subq_4
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_2
+ INNER JOIN (
+ -- 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
- 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
- ON
- DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day
- WHERE DATE_TRUNC('month', subq_2.metric_time__day) = subq_2.metric_time__day
- ) subq_4
- WHERE metric_time__day = '2020-01-01'
+ 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
+ ON
+ DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day
+ WHERE DATE_TRUNC('month', subq_2.metric_time__day) = subq_2.metric_time__day
) subq_5
) subq_6
GROUP BY
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql
index 29518080d..20c53e66b 100644
--- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql
@@ -9,33 +9,36 @@ SELECT
metric_time__month
, bookings_start_of_month AS bookings_at_start_of_month
FROM (
- -- Constrain Output with WHERE
+ -- Join to Time Spine Dataset
-- Pass Only Elements: ['bookings', 'metric_time__month']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
- metric_time__month
- , SUM(bookings) AS bookings_start_of_month
+ DATE_TRUNC('month', subq_11.metric_time__day) AS metric_time__month
+ , SUM(subq_10.bookings) AS bookings_start_of_month
FROM (
- -- Join to Time Spine Dataset
+ -- Filter Time Spine
SELECT
- subq_12.ds AS metric_time__day
- , DATE_TRUNC('month', subq_12.ds) AS metric_time__month
- , subq_10.bookings AS bookings
- FROM ***************************.mf_time_spine subq_12
- INNER JOIN (
- -- Read Elements From Semantic Model 'bookings_source'
- -- Metric Time Dimension 'ds'
+ metric_time__day
+ FROM (
+ -- Time Spine
SELECT
- DATE_TRUNC('day', ds) AS metric_time__day
- , 1 AS bookings
- FROM ***************************.fct_bookings bookings_source_src_28000
- ) subq_10
- ON
- DATE_TRUNC('month', subq_12.ds) = subq_10.metric_time__day
- WHERE DATE_TRUNC('month', subq_12.ds) = subq_12.ds
- ) subq_13
- WHERE metric_time__day = '2020-01-01'
+ ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_12
+ ) subq_13
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_11
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_28000
+ ) subq_10
+ ON
+ DATE_TRUNC('month', subq_11.metric_time__day) = subq_10.metric_time__day
+ WHERE DATE_TRUNC('month', subq_11.metric_time__day) = subq_11.metric_time__day
GROUP BY
- metric_time__month
+ DATE_TRUNC('month', subq_11.metric_time__day)
) subq_17
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql
index 927127c08..34a7fcdb6 100644
--- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql
@@ -30,412 +30,315 @@ FROM (
subq_5.metric_time__month
, subq_5.booking_value
FROM (
- -- Constrain Output with WHERE
+ -- Join to Time Spine Dataset
SELECT
- subq_4.metric_time__day
- , subq_4.metric_time__week
- , subq_4.metric_time__month
- , subq_4.metric_time__quarter
- , subq_4.metric_time__year
- , subq_4.metric_time__extract_year
- , subq_4.metric_time__extract_quarter
- , subq_4.metric_time__extract_month
- , subq_4.metric_time__extract_day
- , subq_4.metric_time__extract_dow
- , subq_4.metric_time__extract_doy
- , subq_4.ds__day
- , subq_4.ds__week
- , subq_4.ds__month
- , subq_4.ds__quarter
- , subq_4.ds__year
- , subq_4.ds__extract_year
- , subq_4.ds__extract_quarter
- , subq_4.ds__extract_month
- , subq_4.ds__extract_day
- , subq_4.ds__extract_dow
- , subq_4.ds__extract_doy
- , subq_4.ds_partitioned__day
- , subq_4.ds_partitioned__week
- , subq_4.ds_partitioned__month
- , subq_4.ds_partitioned__quarter
- , subq_4.ds_partitioned__year
- , subq_4.ds_partitioned__extract_year
- , subq_4.ds_partitioned__extract_quarter
- , subq_4.ds_partitioned__extract_month
- , subq_4.ds_partitioned__extract_day
- , subq_4.ds_partitioned__extract_dow
- , subq_4.ds_partitioned__extract_doy
- , subq_4.paid_at__day
- , subq_4.paid_at__week
- , subq_4.paid_at__month
- , subq_4.paid_at__quarter
- , subq_4.paid_at__year
- , subq_4.paid_at__extract_year
- , subq_4.paid_at__extract_quarter
- , subq_4.paid_at__extract_month
- , subq_4.paid_at__extract_day
- , subq_4.paid_at__extract_dow
- , subq_4.paid_at__extract_doy
- , subq_4.booking__ds__day
- , subq_4.booking__ds__week
- , subq_4.booking__ds__month
- , subq_4.booking__ds__quarter
- , subq_4.booking__ds__year
- , subq_4.booking__ds__extract_year
- , subq_4.booking__ds__extract_quarter
- , subq_4.booking__ds__extract_month
- , subq_4.booking__ds__extract_day
- , subq_4.booking__ds__extract_dow
- , subq_4.booking__ds__extract_doy
- , subq_4.booking__ds_partitioned__day
- , subq_4.booking__ds_partitioned__week
- , subq_4.booking__ds_partitioned__month
- , subq_4.booking__ds_partitioned__quarter
- , subq_4.booking__ds_partitioned__year
- , subq_4.booking__ds_partitioned__extract_year
- , subq_4.booking__ds_partitioned__extract_quarter
- , subq_4.booking__ds_partitioned__extract_month
- , subq_4.booking__ds_partitioned__extract_day
- , subq_4.booking__ds_partitioned__extract_dow
- , subq_4.booking__ds_partitioned__extract_doy
- , subq_4.booking__paid_at__day
- , subq_4.booking__paid_at__week
- , subq_4.booking__paid_at__month
- , subq_4.booking__paid_at__quarter
- , subq_4.booking__paid_at__year
- , subq_4.booking__paid_at__extract_year
- , subq_4.booking__paid_at__extract_quarter
- , subq_4.booking__paid_at__extract_month
- , subq_4.booking__paid_at__extract_day
- , subq_4.booking__paid_at__extract_dow
- , subq_4.booking__paid_at__extract_doy
- , subq_4.listing
- , subq_4.guest
- , subq_4.host
- , subq_4.booking__listing
- , subq_4.booking__guest
- , subq_4.booking__host
- , subq_4.is_instant
- , subq_4.booking__is_instant
- , subq_4.bookings
- , subq_4.instant_bookings
- , subq_4.booking_value
- , subq_4.max_booking_value
- , subq_4.min_booking_value
- , subq_4.bookers
- , subq_4.average_booking_value
- , subq_4.referred_bookings
- , subq_4.median_booking_value
- , subq_4.booking_value_p99
- , subq_4.discrete_booking_value_p99
- , subq_4.approximate_continuous_booking_value_p99
- , subq_4.approximate_discrete_booking_value_p99
+ subq_2.metric_time__day AS metric_time__day
+ , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week
+ , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month
+ , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter
+ , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year
+ , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year
+ , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter
+ , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month
+ , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day
+ , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow
+ , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy
+ , subq_1.ds__day AS ds__day
+ , subq_1.ds__week AS ds__week
+ , subq_1.ds__month AS ds__month
+ , subq_1.ds__quarter AS ds__quarter
+ , subq_1.ds__year AS ds__year
+ , subq_1.ds__extract_year AS ds__extract_year
+ , subq_1.ds__extract_quarter AS ds__extract_quarter
+ , subq_1.ds__extract_month AS ds__extract_month
+ , subq_1.ds__extract_day AS ds__extract_day
+ , subq_1.ds__extract_dow AS ds__extract_dow
+ , subq_1.ds__extract_doy AS ds__extract_doy
+ , subq_1.ds_partitioned__day AS ds_partitioned__day
+ , subq_1.ds_partitioned__week AS ds_partitioned__week
+ , subq_1.ds_partitioned__month AS ds_partitioned__month
+ , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_1.ds_partitioned__year AS ds_partitioned__year
+ , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_1.paid_at__day AS paid_at__day
+ , subq_1.paid_at__week AS paid_at__week
+ , subq_1.paid_at__month AS paid_at__month
+ , subq_1.paid_at__quarter AS paid_at__quarter
+ , subq_1.paid_at__year AS paid_at__year
+ , subq_1.paid_at__extract_year AS paid_at__extract_year
+ , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_1.paid_at__extract_month AS paid_at__extract_month
+ , subq_1.paid_at__extract_day AS paid_at__extract_day
+ , subq_1.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_1.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_1.booking__ds__day AS booking__ds__day
+ , subq_1.booking__ds__week AS booking__ds__week
+ , subq_1.booking__ds__month AS booking__ds__month
+ , subq_1.booking__ds__quarter AS booking__ds__quarter
+ , subq_1.booking__ds__year AS booking__ds__year
+ , subq_1.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_1.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_1.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_1.booking__paid_at__day AS booking__paid_at__day
+ , subq_1.booking__paid_at__week AS booking__paid_at__week
+ , subq_1.booking__paid_at__month AS booking__paid_at__month
+ , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_1.booking__paid_at__year AS booking__paid_at__year
+ , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_1.listing AS listing
+ , subq_1.guest AS guest
+ , subq_1.host AS host
+ , subq_1.booking__listing AS booking__listing
+ , subq_1.booking__guest AS booking__guest
+ , subq_1.booking__host AS booking__host
+ , subq_1.is_instant AS is_instant
+ , subq_1.booking__is_instant AS booking__is_instant
+ , subq_1.bookings AS bookings
+ , subq_1.instant_bookings AS instant_bookings
+ , subq_1.booking_value AS booking_value
+ , subq_1.max_booking_value AS max_booking_value
+ , subq_1.min_booking_value AS min_booking_value
+ , subq_1.bookers AS bookers
+ , subq_1.average_booking_value AS average_booking_value
+ , subq_1.referred_bookings AS referred_bookings
+ , subq_1.median_booking_value AS median_booking_value
+ , subq_1.booking_value_p99 AS booking_value_p99
+ , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
FROM (
- -- Join to Time Spine Dataset
+ -- Filter Time Spine
SELECT
- subq_2.metric_time__day AS metric_time__day
- , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week
- , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month
- , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter
- , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year
- , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year
- , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter
- , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month
- , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day
- , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow
- , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy
- , subq_1.ds__day AS ds__day
- , subq_1.ds__week AS ds__week
- , subq_1.ds__month AS ds__month
- , subq_1.ds__quarter AS ds__quarter
- , subq_1.ds__year AS ds__year
- , subq_1.ds__extract_year AS ds__extract_year
- , subq_1.ds__extract_quarter AS ds__extract_quarter
- , subq_1.ds__extract_month AS ds__extract_month
- , subq_1.ds__extract_day AS ds__extract_day
- , subq_1.ds__extract_dow AS ds__extract_dow
- , subq_1.ds__extract_doy AS ds__extract_doy
- , subq_1.ds_partitioned__day AS ds_partitioned__day
- , subq_1.ds_partitioned__week AS ds_partitioned__week
- , subq_1.ds_partitioned__month AS ds_partitioned__month
- , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter
- , subq_1.ds_partitioned__year AS ds_partitioned__year
- , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year
- , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
- , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month
- , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day
- , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
- , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
- , subq_1.paid_at__day AS paid_at__day
- , subq_1.paid_at__week AS paid_at__week
- , subq_1.paid_at__month AS paid_at__month
- , subq_1.paid_at__quarter AS paid_at__quarter
- , subq_1.paid_at__year AS paid_at__year
- , subq_1.paid_at__extract_year AS paid_at__extract_year
- , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter
- , subq_1.paid_at__extract_month AS paid_at__extract_month
- , subq_1.paid_at__extract_day AS paid_at__extract_day
- , subq_1.paid_at__extract_dow AS paid_at__extract_dow
- , subq_1.paid_at__extract_doy AS paid_at__extract_doy
- , subq_1.booking__ds__day AS booking__ds__day
- , subq_1.booking__ds__week AS booking__ds__week
- , subq_1.booking__ds__month AS booking__ds__month
- , subq_1.booking__ds__quarter AS booking__ds__quarter
- , subq_1.booking__ds__year AS booking__ds__year
- , subq_1.booking__ds__extract_year AS booking__ds__extract_year
- , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter
- , subq_1.booking__ds__extract_month AS booking__ds__extract_month
- , subq_1.booking__ds__extract_day AS booking__ds__extract_day
- , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow
- , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy
- , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day
- , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week
- , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month
- , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
- , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year
- , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
- , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
- , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
- , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
- , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
- , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
- , subq_1.booking__paid_at__day AS booking__paid_at__day
- , subq_1.booking__paid_at__week AS booking__paid_at__week
- , subq_1.booking__paid_at__month AS booking__paid_at__month
- , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter
- , subq_1.booking__paid_at__year AS booking__paid_at__year
- , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year
- , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
- , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month
- , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day
- , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
- , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
- , subq_1.listing AS listing
- , subq_1.guest AS guest
- , subq_1.host AS host
- , subq_1.booking__listing AS booking__listing
- , subq_1.booking__guest AS booking__guest
- , subq_1.booking__host AS booking__host
- , subq_1.is_instant AS is_instant
- , subq_1.booking__is_instant AS booking__is_instant
- , subq_1.bookings AS bookings
- , subq_1.instant_bookings AS instant_bookings
- , subq_1.booking_value AS booking_value
- , subq_1.max_booking_value AS max_booking_value
- , subq_1.min_booking_value AS min_booking_value
- , subq_1.bookers AS bookers
- , subq_1.average_booking_value AS average_booking_value
- , subq_1.referred_bookings AS referred_bookings
- , subq_1.median_booking_value AS median_booking_value
- , subq_1.booking_value_p99 AS booking_value_p99
- , subq_1.discrete_booking_value_p99 AS discrete_booking_value_p99
- , subq_1.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
- , subq_1.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ subq_4.metric_time__day
FROM (
-- Time Spine
SELECT
subq_3.ds AS metric_time__day
FROM ***************************.mf_time_spine subq_3
- ) subq_2
- INNER JOIN (
- -- Metric Time Dimension 'ds'
+ ) subq_4
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_2
+ INNER JOIN (
+ -- 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
- 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
- ON
- subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day
- ) subq_4
- WHERE metric_time__day = '2020-01-01'
+ 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
+ ON
+ subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day
) subq_5
) subq_6
GROUP BY
diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql
index 63f543a97..637ee293c 100644
--- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql
+++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql
@@ -15,28 +15,31 @@ FROM (
, MAX(subq_24.booking_value) AS booking_value
, MAX(subq_30.bookers) AS bookers
FROM (
- -- Constrain Output with WHERE
+ -- Join to Time Spine Dataset
-- Pass Only Elements: ['booking_value', 'metric_time__month']
-- Aggregate Measures
-- Compute Metrics via Expressions
SELECT
- metric_time__month
- , SUM(booking_value) AS booking_value
+ DATE_TRUNC('month', subq_18.metric_time__day) AS metric_time__month
+ , SUM(bookings_source_src_28000.booking_value) AS booking_value
FROM (
- -- Join to Time Spine Dataset
+ -- Filter Time Spine
SELECT
- subq_19.ds AS metric_time__day
- , DATE_TRUNC('month', subq_19.ds) AS metric_time__month
- , bookings_source_src_28000.booking_value AS booking_value
- FROM ***************************.mf_time_spine subq_19
- INNER JOIN
- ***************************.fct_bookings bookings_source_src_28000
- ON
- subq_19.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds)
- ) subq_20
- WHERE metric_time__day = '2020-01-01'
+ metric_time__day
+ FROM (
+ -- Time Spine
+ SELECT
+ ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_19
+ ) subq_20
+ WHERE metric_time__day = '2020-01-01'
+ ) subq_18
+ INNER JOIN
+ ***************************.fct_bookings bookings_source_src_28000
+ ON
+ subq_18.metric_time__day - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds)
GROUP BY
- metric_time__month
+ DATE_TRUNC('month', subq_18.metric_time__day)
) subq_24
FULL OUTER JOIN (
-- Constrain Output with WHERE
diff --git a/tests_metricflow/snapshots/test_offset_metrics.py/str/DuckDB/test_nested_offset_to_grain_metric_with_tiered_filters__query_output.txt b/tests_metricflow/snapshots/test_offset_metrics.py/str/DuckDB/test_nested_offset_to_grain_metric_with_tiered_filters__query_output.txt
new file mode 100644
index 000000000..4c7fa10c2
--- /dev/null
+++ b/tests_metricflow/snapshots/test_offset_metrics.py/str/DuckDB/test_nested_offset_to_grain_metric_with_tiered_filters__query_output.txt
@@ -0,0 +1,35 @@
+test_name: test_nested_offset_to_grain_metric_with_tiered_filters
+test_filename: test_offset_metrics.py
+---
+metric_time__day bookings_offset_to_grain_twice_with_tiered_filters
+------------------- ----------------------------------------------------
+2020-01-01T00:00:00 None
+2020-01-02T00:00:00 None
+2020-01-06T00:00:00 None
+2020-01-07T00:00:00 None
+2020-01-08T00:00:00 None
+2020-01-09T00:00:00 None
+2020-01-10T00:00:00 None
+2020-01-11T00:00:00 None
+2020-01-12T00:00:00 None
+2020-01-13T00:00:00 None
+2020-01-14T00:00:00 None
+2020-01-15T00:00:00 None
+2020-01-16T00:00:00 None
+2020-01-17T00:00:00 None
+2020-01-18T00:00:00 None
+2020-01-19T00:00:00 None
+2020-01-20T00:00:00 None
+2020-01-21T00:00:00 None
+2020-01-22T00:00:00 None
+2020-01-23T00:00:00 None
+2020-01-24T00:00:00 None
+2020-01-25T00:00:00 None
+2020-01-26T00:00:00 None
+2020-01-27T00:00:00 None
+2020-01-28T00:00:00 None
+2020-01-29T00:00:00 None
+2020-01-30T00:00:00 None
+2020-01-31T00:00:00 None
+2020-02-01T00:00:00 None
+2020-02-02T00:00:00 None
diff --git a/tests_metricflow/snapshots/test_offset_metrics.py/str/DuckDB/test_nested_offset_window_metric_with_tiered_filters__query_output.txt b/tests_metricflow/snapshots/test_offset_metrics.py/str/DuckDB/test_nested_offset_window_metric_with_tiered_filters__query_output.txt
new file mode 100644
index 000000000..7cd9e2042
--- /dev/null
+++ b/tests_metricflow/snapshots/test_offset_metrics.py/str/DuckDB/test_nested_offset_window_metric_with_tiered_filters__query_output.txt
@@ -0,0 +1,5 @@
+test_name: test_nested_offset_window_metric_with_tiered_filters
+test_filename: test_offset_metrics.py
+---
+metric_time__day bookings_offset_twice_with_tiered_filters
+------------------ -------------------------------------------