From 043d194d2860d415d56dc646b2796c730d8f93ae Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 27 Feb 2024 18:12:33 -0800 Subject: [PATCH 1/8] Changelog --- .changes/unreleased/Fixes-20240227-181223.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changes/unreleased/Fixes-20240227-181223.yaml diff --git a/.changes/unreleased/Fixes-20240227-181223.yaml b/.changes/unreleased/Fixes-20240227-181223.yaml new file mode 100644 index 0000000000..456180ee50 --- /dev/null +++ b/.changes/unreleased/Fixes-20240227-181223.yaml @@ -0,0 +1,7 @@ +kind: Fixes +body: Enable querying offset metric with multiple agg_time_dimensions at once. Also + fixes a bug when filtering by a different grain than the group by grain. +time: 2024-02-27T18:12:23.601203-08:00 +custom: + Author: courtneyholcomb + Issue: 1052 1053 From 6a39795b9ae5c945368f11f16bc8f3273249b0a7 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 27 Feb 2024 18:19:19 -0800 Subject: [PATCH 2/8] Write tests for existing functionality (some failing) & generate snapshots --- .../builder/test_dataflow_plan_builder.py | 65 ++ .../simple_manifest/metrics.yaml | 13 + .../query_output/test_offset_metrics.py | 58 ++ .../test_derived_metric_rendering.py | 110 ++++ ...ry_have_different_granularities__dfp_0.xml | 111 ++++ ...ry_have_different_granularities__dfp_0.xml | 187 ++++++ ...n_metric_multiple_granularities__plan0.sql | 336 ++++++++++ ...ultiple_granularities__plan0_optimized.sql | 37 ++ ...w_metric_multiple_granularities__plan0.sql | 575 ++++++++++++++++++ ...ultiple_granularities__plan0_optimized.sql | 64 ++ ...h_multiple_granularities__query_output.txt | 3 + ..._with_single_granularity__query_output.txt | 63 ++ 12 files changed, 1622 insertions(+) create mode 100644 metricflow/test/integration/query_output/test_offset_metrics.py create mode 100644 metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml create mode 100644 metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_single_granularity__query_output.txt diff --git a/metricflow/test/dataflow/builder/test_dataflow_plan_builder.py b/metricflow/test/dataflow/builder/test_dataflow_plan_builder.py index 01494ab5b7..ff7dd5cab2 100644 --- a/metricflow/test/dataflow/builder/test_dataflow_plan_builder.py +++ b/metricflow/test/dataflow/builder/test_dataflow_plan_builder.py @@ -5,6 +5,7 @@ import pytest from _pytest.fixtures import FixtureRequest +from dbt_semantic_interfaces.implementations.filters.where_filter import PydanticWhereFilter from dbt_semantic_interfaces.naming.keywords import METRIC_TIME_ELEMENT_NAME from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity @@ -1117,4 +1118,68 @@ def test_min_max_only_time_year( ) +@pytest.mark.sql_engine_snapshot +def test_offset_window_metric_filter_and_query_have_different_granularities( + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + dataflow_plan_builder: DataflowPlanBuilder, + query_parser: MetricFlowQueryParser, + create_source_tables: bool, +) -> None: + """Test a query where an offset window metric is queried with one granularity and filtered by a different one.""" + query_spec = query_parser.parse_and_validate_query( + metric_names=("booking_fees_last_week_per_booker_this_week",), + group_by_names=("metric_time__month",), + where_constraint=PydanticWhereFilter( + where_sql_template=("{{ TimeDimension('metric_time', 'day') }} = '2020-01-01'") + ), + ) + dataflow_plan = dataflow_plan_builder.build_plan(query_spec) + + assert_plan_snapshot_text_equal( + request=request, + mf_test_session_state=mf_test_session_state, + plan=dataflow_plan, + plan_snapshot_text=dataflow_plan.text_structure(), + ) + + display_graph_if_requested( + request=request, + mf_test_session_state=mf_test_session_state, + dag_graph=dataflow_plan, + ) + + +@pytest.mark.sql_engine_snapshot +def test_offset_to_grain_metric_filter_and_query_have_different_granularities( + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + dataflow_plan_builder: DataflowPlanBuilder, + query_parser: MetricFlowQueryParser, + create_source_tables: bool, +) -> None: + """Test a query where an offset to grain metric is queried with one granularity and filtered by a different one.""" + query_spec = query_parser.parse_and_validate_query( + metric_names=("bookings_at_start_of_month",), + group_by_names=("metric_time__month",), + where_constraint=PydanticWhereFilter( + where_sql_template=("{{ TimeDimension('metric_time', 'day') }} = '2020-01-01'") + ), + ) + dataflow_plan = dataflow_plan_builder.build_plan(query_spec) + + assert_plan_snapshot_text_equal( + request=request, + mf_test_session_state=mf_test_session_state, + plan=dataflow_plan, + plan_snapshot_text=dataflow_plan.text_structure(), + ) + + display_graph_if_requested( + request=request, + mf_test_session_state=mf_test_session_state, + dag_graph=dataflow_plan, + ) + + # TODO: add test for min max metric_time (various granularities) when supported diff --git a/metricflow/test/fixtures/semantic_manifest_yamls/simple_manifest/metrics.yaml b/metricflow/test/fixtures/semantic_manifest_yamls/simple_manifest/metrics.yaml index 931e32703e..3648c71ec6 100644 --- a/metricflow/test/fixtures/semantic_manifest_yamls/simple_manifest/metrics.yaml +++ b/metricflow/test/fixtures/semantic_manifest_yamls/simple_manifest/metrics.yaml @@ -675,6 +675,19 @@ metric: - name: bookings_offset_once offset_window: 2 days --- +metric: + name: bookings_at_start_of_month + description: | + Derived metric with offset to grain - single input metric. + Not a particularly useful metric but it allows us to isolate behavior for offset to grain. + type: derived + type_params: + expr: bookings_start_of_month + metrics: + - name: bookings + offset_to_grain: month + alias: bookings_start_of_month +--- metric: name: booking_fees_since_start_of_month description: nested derived metric with offset and multiple input metrics diff --git a/metricflow/test/integration/query_output/test_offset_metrics.py b/metricflow/test/integration/query_output/test_offset_metrics.py new file mode 100644 index 0000000000..84ad816e26 --- /dev/null +++ b/metricflow/test/integration/query_output/test_offset_metrics.py @@ -0,0 +1,58 @@ +from __future__ import annotations + +import pytest +from _pytest.fixtures import FixtureRequest + +from metricflow.engine.metricflow_engine import MetricFlowQueryRequest +from metricflow.protocols.sql_client import SqlClient +from metricflow.test.fixtures.setup_fixtures import MetricFlowTestSessionState +from metricflow.test.integration.conftest import IntegrationTestHelpers +from metricflow.test.snapshot_utils import assert_str_snapshot_equal + + +@pytest.mark.sql_engine_snapshot +def test_offset_to_grain_with_single_granularity( # noqa: D + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + sql_client: SqlClient, + it_helpers: IntegrationTestHelpers, +) -> None: + query_result = it_helpers.mf_engine.query( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=["bookings_at_start_of_month"], + group_by_names=["metric_time__day"], + ) + ) + assert query_result.result_df is not None, "Unexpected empty result." + + assert_str_snapshot_equal( + request=request, + mf_test_session_state=mf_test_session_state, + snapshot_id="query_output", + snapshot_str=query_result.result_df.to_string(), + sql_engine=sql_client.sql_engine_type, + ) + + +@pytest.mark.sql_engine_snapshot +def test_offset_to_grain_with_multiple_granularities( # noqa: D + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + sql_client: SqlClient, + it_helpers: IntegrationTestHelpers, +) -> None: + query_result = it_helpers.mf_engine.query( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=["bookings_at_start_of_month"], + group_by_names=["metric_time__day", "metric_time__month", "metric_time__year"], + ) + ) + assert query_result.result_df is not None, "Unexpected empty result." + + assert_str_snapshot_equal( + request=request, + mf_test_session_state=mf_test_session_state, + snapshot_id="query_output", + snapshot_str=query_result.result_df.to_string(), + sql_engine=sql_client.sql_engine_type, + ) diff --git a/metricflow/test/query_rendering/test_derived_metric_rendering.py b/metricflow/test/query_rendering/test_derived_metric_rendering.py index 5fc8f52bd5..05825721fe 100644 --- a/metricflow/test/query_rendering/test_derived_metric_rendering.py +++ b/metricflow/test/query_rendering/test_derived_metric_rendering.py @@ -701,3 +701,113 @@ def test_nested_fill_nulls_without_time_spine_multi_metric( # noqa: D sql_client=sql_client, node=dataflow_plan.sink_output_nodes[0].parent_node, ) + + +@pytest.mark.sql_engine_snapshot +def test_offset_window_metric_multiple_granularities( + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, + query_parser: MetricFlowQueryParser, + create_source_tables: bool, +) -> None: + """Test a query where an offset window metric is queried with multiple granularities.""" + query_spec = query_parser.parse_and_validate_query( + metric_names=("booking_fees_last_week_per_booker_this_week",), + group_by_names=("metric_time__day", "metric_time__month", "metric_time__year"), + ) + dataflow_plan = dataflow_plan_builder.build_plan(query_spec) + + convert_and_check( + request=request, + mf_test_session_state=mf_test_session_state, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + node=dataflow_plan.sink_output_nodes[0].parent_node, + ) + + +@pytest.mark.sql_engine_snapshot +def test_offset_to_grain_metric_multiple_granularities( + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, + query_parser: MetricFlowQueryParser, + create_source_tables: bool, +) -> None: + """Test a query where an offset to grain metric is queried with multiple granularities.""" + query_spec = query_parser.parse_and_validate_query( + metric_names=("bookings_at_start_of_month",), + group_by_names=("metric_time__day", "metric_time__month", "metric_time__year"), + ) + dataflow_plan = dataflow_plan_builder.build_plan(query_spec) + + convert_and_check( + request=request, + mf_test_session_state=mf_test_session_state, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + node=dataflow_plan.sink_output_nodes[0].parent_node, + ) + + +@pytest.mark.sql_engine_snapshot +def test_offset_window_metric_filter_and_query_have_different_granularities( + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, + query_parser: MetricFlowQueryParser, + create_source_tables: bool, +) -> None: + """Test a query where an offset window metric is queried with one granularity and filtered by a different one.""" + query_spec = query_parser.parse_and_validate_query( + metric_names=("booking_fees_last_week_per_booker_this_week",), + group_by_names=("metric_time__month",), + where_constraint=PydanticWhereFilter( + where_sql_template=("{{ TimeDimension('metric_time', 'day') }} = '2020-01-01'") + ), + ) + dataflow_plan = dataflow_plan_builder.build_plan(query_spec) + + convert_and_check( + request=request, + mf_test_session_state=mf_test_session_state, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + node=dataflow_plan.sink_output_nodes[0].parent_node, + ) + + +@pytest.mark.sql_engine_snapshot +def test_offset_to_grain_metric_filter_and_query_have_different_granularities( + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, + query_parser: MetricFlowQueryParser, + create_source_tables: bool, +) -> None: + """Test a query where an offset to grain metric is queried with one granularity and filtered by a different one.""" + query_spec = query_parser.parse_and_validate_query( + metric_names=("bookings_at_start_of_month",), + group_by_names=("metric_time__month",), + where_constraint=PydanticWhereFilter( + where_sql_template=("{{ TimeDimension('metric_time', 'day') }} = '2020-01-01'") + ), + ) + dataflow_plan = dataflow_plan_builder.build_plan(query_spec) + + convert_and_check( + request=request, + mf_test_session_state=mf_test_session_state, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + node=dataflow_plan.sink_output_nodes[0].parent_node, + ) diff --git a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml new file mode 100644 index 0000000000..83163f27c9 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_to_grain_metric_filter_and_query_have_different_granularities__dfp_0.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml new file mode 100644 index 0000000000..1af03c7933 --- /dev/null +++ b/metricflow/test/snapshots/test_dataflow_plan_builder.py/DataflowPlan/test_offset_window_metric_filter_and_query_have_different_granularities__dfp_0.xml @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..d3f51452e3 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -0,0 +1,336 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , 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 ( + -- Time Spine + SELECT + 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 ( + -- 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 + ) OR ( + DATE_TRUNC('year', subq_2.metric_time__day) = subq_2.metric_time__day + ) + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 +) subq_7 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..35be9c4dbc --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,37 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_11.ds AS metric_time__day + , DATE_TRUNC('month', subq_11.ds) AS metric_time__month + , DATE_TRUNC('year', subq_11.ds) AS metric_time__year + , SUM(subq_9.bookings) AS bookings_start_of_month + FROM ***************************.mf_time_spine subq_11 + 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_9 + ON + DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + WHERE ( + DATE_TRUNC('month', subq_11.ds) = subq_11.ds + ) OR ( + DATE_TRUNC('year', subq_11.ds) = subq_11.ds + ) + GROUP BY + subq_11.ds + , DATE_TRUNC('month', subq_11.ds) + , DATE_TRUNC('year', subq_11.ds) +) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..8ea23101e2 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql @@ -0,0 +1,575 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , subq_13.metric_time__month + , subq_13.metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) AS metric_time__month + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) AS metric_time__year + , MAX(subq_7.booking_value) AS booking_value + , MAX(subq_12.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.booking_value + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , 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 ( + -- Time Spine + SELECT + 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 ( + -- 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 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 + ) subq_7 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + , subq_11.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + , COUNT(DISTINCT subq_10.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_9.metric_time__day + , subq_9.metric_time__month + , subq_9.metric_time__year + , subq_9.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.ds_partitioned__day + , subq_8.ds_partitioned__week + , subq_8.ds_partitioned__month + , subq_8.ds_partitioned__quarter + , subq_8.ds_partitioned__year + , subq_8.ds_partitioned__extract_year + , subq_8.ds_partitioned__extract_quarter + , subq_8.ds_partitioned__extract_month + , subq_8.ds_partitioned__extract_day + , subq_8.ds_partitioned__extract_dow + , subq_8.ds_partitioned__extract_doy + , subq_8.paid_at__day + , subq_8.paid_at__week + , subq_8.paid_at__month + , subq_8.paid_at__quarter + , subq_8.paid_at__year + , subq_8.paid_at__extract_year + , subq_8.paid_at__extract_quarter + , subq_8.paid_at__extract_month + , subq_8.paid_at__extract_day + , subq_8.paid_at__extract_dow + , subq_8.paid_at__extract_doy + , subq_8.booking__ds__day + , subq_8.booking__ds__week + , subq_8.booking__ds__month + , subq_8.booking__ds__quarter + , subq_8.booking__ds__year + , subq_8.booking__ds__extract_year + , subq_8.booking__ds__extract_quarter + , subq_8.booking__ds__extract_month + , subq_8.booking__ds__extract_day + , subq_8.booking__ds__extract_dow + , subq_8.booking__ds__extract_doy + , subq_8.booking__ds_partitioned__day + , subq_8.booking__ds_partitioned__week + , subq_8.booking__ds_partitioned__month + , subq_8.booking__ds_partitioned__quarter + , subq_8.booking__ds_partitioned__year + , subq_8.booking__ds_partitioned__extract_year + , subq_8.booking__ds_partitioned__extract_quarter + , subq_8.booking__ds_partitioned__extract_month + , subq_8.booking__ds_partitioned__extract_day + , subq_8.booking__ds_partitioned__extract_dow + , subq_8.booking__ds_partitioned__extract_doy + , subq_8.booking__paid_at__day + , subq_8.booking__paid_at__week + , subq_8.booking__paid_at__month + , subq_8.booking__paid_at__quarter + , subq_8.booking__paid_at__year + , subq_8.booking__paid_at__extract_year + , subq_8.booking__paid_at__extract_quarter + , subq_8.booking__paid_at__extract_month + , subq_8.booking__paid_at__extract_day + , subq_8.booking__paid_at__extract_dow + , subq_8.booking__paid_at__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy + , subq_8.listing + , subq_8.guest + , subq_8.host + , subq_8.booking__listing + , subq_8.booking__guest + , subq_8.booking__host + , subq_8.is_instant + , subq_8.booking__is_instant + , subq_8.bookings + , subq_8.instant_bookings + , subq_8.booking_value + , subq_8.max_booking_value + , subq_8.min_booking_value + , subq_8.bookers + , subq_8.average_booking_value + , subq_8.referred_bookings + , subq_8.median_booking_value + , subq_8.booking_value_p99 + , subq_8.discrete_booking_value_p99 + , subq_8.approximate_continuous_booking_value_p99 + , subq_8.approximate_discrete_booking_value_p99 + 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_8 + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + ) subq_11 + ) subq_12 + ON + ( + subq_7.metric_time__day = subq_12.metric_time__day + ) AND ( + subq_7.metric_time__month = subq_12.metric_time__month + ) AND ( + subq_7.metric_time__year = subq_12.metric_time__year + ) + GROUP BY + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..7a9df9d3d5 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,64 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) AS metric_time__day + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) AS metric_time__month + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) AS metric_time__year + , MAX(subq_21.booking_value) AS booking_value + , MAX(subq_26.bookers) AS bookers + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_17.ds AS metric_time__day + , DATE_TRUNC('month', subq_17.ds) AS metric_time__month + , DATE_TRUNC('year', subq_17.ds) AS metric_time__year + , SUM(bookings_source_src_28000.booking_value) AS booking_value + FROM ***************************.mf_time_spine subq_17 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + subq_17.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + GROUP BY + subq_17.ds + , DATE_TRUNC('month', subq_17.ds) + , DATE_TRUNC('year', subq_17.ds) + ) subq_21 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , DATE_TRUNC('year', ds) AS metric_time__year + , COUNT(DISTINCT guest_id) AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + , DATE_TRUNC('month', ds) + , DATE_TRUNC('year', ds) + ) subq_26 + ON + ( + subq_21.metric_time__day = subq_26.metric_time__day + ) AND ( + subq_21.metric_time__month = subq_26.metric_time__month + ) AND ( + subq_21.metric_time__year = subq_26.metric_time__year + ) + GROUP BY + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) +) subq_27 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt new file mode 100644 index 0000000000..02ed088335 --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt @@ -0,0 +1,3 @@ + metric_time__day metric_time__month metric_time__year bookings_at_start_of_month +0 2019-12-01 2019-12-01 2019-01-01 1 +1 2020-01-01 2020-01-01 2020-01-01 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_single_granularity__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_single_granularity__query_output.txt new file mode 100644 index 0000000000..b90b143ca9 --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_single_granularity__query_output.txt @@ -0,0 +1,63 @@ + metric_time__day bookings_at_start_of_month +0 2019-12-06 1 +1 2019-12-09 1 +2 2019-12-16 1 +3 2019-12-19 1 +4 2020-01-28 5 +5 2019-12-10 1 +6 2019-12-11 1 +7 2019-12-24 1 +8 2019-12-31 1 +9 2020-01-02 5 +10 2020-01-11 5 +11 2020-01-22 5 +12 2019-12-03 1 +13 2019-12-17 1 +14 2019-12-18 1 +15 2019-12-23 1 +16 2019-12-26 1 +17 2019-12-27 1 +18 2020-01-10 5 +19 2020-01-24 5 +20 2020-01-25 5 +21 2019-12-01 1 +22 2019-12-05 1 +23 2019-12-14 1 +24 2020-01-01 5 +25 2020-01-05 5 +26 2020-01-08 5 +27 2020-01-16 5 +28 2020-01-18 5 +29 2020-01-29 5 +30 2019-12-04 1 +31 2019-12-12 1 +32 2019-12-21 1 +33 2019-12-25 1 +34 2019-12-28 1 +35 2019-12-30 1 +36 2020-01-09 5 +37 2020-01-13 5 +38 2020-01-20 5 +39 2020-01-27 5 +40 2019-12-02 1 +41 2019-12-13 1 +42 2019-12-20 1 +43 2020-01-03 5 +44 2020-01-06 5 +45 2020-01-07 5 +46 2020-01-14 5 +47 2020-01-15 5 +48 2020-01-21 5 +49 2020-01-23 5 +50 2020-01-26 5 +51 2020-01-31 5 +52 2019-12-07 1 +53 2019-12-29 1 +54 2020-01-12 5 +55 2019-12-08 1 +56 2019-12-15 1 +57 2019-12-22 1 +58 2020-01-04 5 +59 2020-01-17 5 +60 2020-01-19 5 +61 2020-01-30 5 From 026b382a956ad83034a846a5f198386036fb2062 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 27 Feb 2024 18:24:40 -0800 Subject: [PATCH 3/8] Update dataflow to SQL to allow multiple agg_time_dimensions --- metricflow/plan_conversion/dataflow_to_sql.py | 73 ++++++++++++------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index d5c33c13b0..47046c41e0 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -1298,8 +1298,18 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet parent_alias=parent_alias, ) - # Select all instances from the parent data set, EXCEPT the requested agg_time_dimension. - # The agg_time_dimension will be selected from the time spine data set. + # Select all instances from the parent data set, EXCEPT agg_time_dimensions. + # The agg_time_dimensions will be selected from the time spine data set. + time_dimensions_to_select_from_parent: Tuple[TimeDimensionInstance, ...] = () + time_dimensions_to_select_from_time_spine: Tuple[TimeDimensionInstance, ...] = () + for time_dimension_instance in parent_data_set.instance_set.time_dimension_instances: + if ( + time_dimension_instance.spec.element_name == agg_time_element_name + and time_dimension_instance.spec.entity_links == agg_time_entity_links + ): + time_dimensions_to_select_from_time_spine += (time_dimension_instance,) + else: + time_dimensions_to_select_from_parent += (time_dimension_instance,) parent_instance_set = InstanceSet( measure_instances=parent_data_set.instance_set.measure_instances, dimension_instances=parent_data_set.instance_set.dimension_instances, @@ -1331,35 +1341,48 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet SqlColumnReference(table_alias=time_spine_alias, column_name=time_spine_dim_instance.spec.qualified_name) ) - # Add requested granularities (if different from time_spine) and date_parts to time spine column. time_spine_select_columns = [] time_spine_dim_instances = [] - where: Optional[SqlExpressionNode] = None - for requested_time_dimension_spec in node.requested_agg_time_dimension_specs: - # Apply granularity to time spine column select expression. - if requested_time_dimension_spec.time_granularity == time_spine_dim_instance.spec.time_granularity: - select_expr: SqlExpressionNode = time_spine_column_select_expr - else: - select_expr = SqlDateTruncExpression( - time_granularity=requested_time_dimension_spec.time_granularity, arg=time_spine_column_select_expr + where_filter: Optional[SqlExpressionNode] = None + + # If offset_to_grain is used, will need to filter down to rows that match selected granularities. + # Does not apply if one of the granularities selected matches the time spine column granularity. + need_where_filter = ( + node.offset_to_grain and time_spine_dim_instance.spec not in node.requested_agg_time_dimension_specs + ) + + # Add requested granularities (if different from time_spine) and date_parts to time spine column. + for time_dimension_instance in time_dimensions_to_select_from_time_spine: + time_dimension_spec = time_dimension_instance.spec + + # Apply grain to time spine column select expression, unless grain already matches time spine column. + select_expr: SqlExpressionNode = ( + time_spine_column_select_expr + if time_dimension_spec.time_granularity == time_spine_dim_instance.spec.time_granularity + else SqlDateTruncExpression( + time_granularity=time_dimension_spec.time_granularity, arg=time_spine_column_select_expr ) - if node.offset_to_grain: - # Filter down to one row per granularity period - new_filter = SqlComparisonExpression( - left_expr=select_expr, comparison=SqlComparison.EQUALS, right_expr=time_spine_column_select_expr - ) - if not where: - where = new_filter - else: - where = SqlLogicalExpression(operator=SqlLogicalOperator.OR, args=(where, new_filter)) + ) + # Filter down to one row per granularity period requested in the group by. Any other granularities + # included here will be filtered out in later nodes so should not be included in where filter. + if need_where_filter and time_dimension_spec in node.requested_agg_time_dimension_specs: + new_where_filter = SqlComparisonExpression( + left_expr=select_expr, comparison=SqlComparison.EQUALS, right_expr=time_spine_column_select_expr + ) + where_filter = ( + SqlLogicalExpression(operator=SqlLogicalOperator.OR, args=(where_filter, new_where_filter)) + if where_filter + else new_where_filter + ) + # Apply date_part to time spine column select expression. - if requested_time_dimension_spec.date_part: - select_expr = SqlExtractExpression(date_part=requested_time_dimension_spec.date_part, arg=select_expr) + if time_dimension_spec.date_part: + select_expr = SqlExtractExpression(date_part=time_dimension_spec.date_part, arg=select_expr) time_dim_spec = TimeDimensionSpec( element_name=time_spine_dim_instance.spec.element_name, entity_links=time_spine_dim_instance.spec.entity_links, - time_granularity=requested_time_dimension_spec.time_granularity, - date_part=requested_time_dimension_spec.date_part, + time_granularity=time_dimension_spec.time_granularity, + date_part=time_dimension_spec.date_part, aggregation_state=time_spine_dim_instance.spec.aggregation_state, ) time_spine_dim_instance = TimeDimensionInstance( @@ -1383,7 +1406,7 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet joins_descs=(join_description,), group_bys=(), order_bys=(), - where=where, + where=where_filter, ), ) From df5e0d924e590ef2214a8b3f06adb66d382dc655 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 27 Feb 2024 18:26:12 -0800 Subject: [PATCH 4/8] Generate snapshots with changes --- ...set_metric_with_time_constraint__plan0.sql | 10 + ...nth_dimension_and_offset_window__plan0.sql | 5 + ...ved_metric_with_offset_to_grain__plan0.sql | 10 + ...offset_to_grain_and_granularity__plan0.sql | 12 +- ...rived_metric_with_offset_window__plan0.sql | 10 + ...h_offset_window_and_granularity__plan0.sql | 12 +- ...fset_window_and_offset_to_grain__plan0.sql | 20 + ...offset_to_grain_and_granularity__plan0.sql | 24 +- ...h_offset_window_and_time_filter__plan0.sql | 10 + ...erived_offset_cumulative_metric__plan0.sql | 10 + ...offset_metric_with_agg_time_dim__plan0.sql | 10 + ...et_metric_with_one_input_metric__plan0.sql | 10 + ...d_where_constraint_not_selected__plan0.sql | 10 + .../DuckDB/test_nested_offsets__plan0.sql | 10 + ...ed_offsets_with_time_constraint__plan0.sql | 10 + ...d_offsets_with_where_constraint__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 345 +++++++++++ ...fferent_granularities__plan0_optimized.sql | 36 ++ ...n_metric_multiple_granularities__plan0.sql | 13 +- ...ultiple_granularities__plan0_optimized.sql | 5 - ...fset_to_grain_with_agg_time_dim__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 585 ++++++++++++++++++ ...fferent_granularities__plan0_optimized.sql | 62 ++ ...w_metric_multiple_granularities__plan0.sql | 8 + ...offset_window_with_agg_time_dim__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...fill_nulls_for_one_input_metric__plan0.sql | 10 + ...st_offset_window_with_date_part__plan0.sql | 12 +- ...h_multiple_granularities__query_output.txt | 66 +- 29 files changed, 1337 insertions(+), 18 deletions(-) create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index b2c5912232..a366dbfa75 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -26,6 +26,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 243d2d1af4..c024f5be49 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -21,6 +21,11 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__month AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month , subq_1.monthly_ds__quarter AS monthly_ds__quarter , subq_1.monthly_ds__year AS monthly_ds__year diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql index 36c1caf422..c7ab524c14 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 328247b22e..d1d423597c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql index e258c3e3e1..a740353bfc 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 1f27b4fb18..aed26331bc 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 23552032b5..bd625c2bce 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -27,6 +27,16 @@ 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 DATE_TRUNC('day', 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 @@ -342,6 +352,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index ceb6876814..8fcd5b5b70 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -26,7 +26,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + 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 DATE_TRUNC('day', 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 @@ -342,7 +352,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index bc137eca65..30e762031e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -254,6 +254,16 @@ FROM ( -- Join to Time Spine Dataset 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql index 06eead6220..bd4671a650 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql index aa7ea1e0dd..e60b7053b8 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -27,6 +27,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_2.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(isodow FROM subq_2.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_2.booking__ds__day) AS booking__ds__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql index 9c53e70d60..6dd8959273 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index d5dc31c413..f34d48abce 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -53,6 +53,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql index b999d7b87f..f75f60c01d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql @@ -37,6 +37,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql index c0ba874670..06ad04b135 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql @@ -38,6 +38,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql index 2bd4dfdf68..342e0c87d5 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql @@ -42,6 +42,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..017e0f1383 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,345 @@ +-- Compute Metrics via Expressions +SELECT + subq_9.metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.bookings + 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 DATE_TRUNC('day', 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 ( + -- Time Spine + SELECT + 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 ( + -- 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 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 +) subq_9 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..bfd3b8fbce --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,36 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(bookings) AS bookings_start_of_month + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_13.ds AS metric_time__day + , DATE_TRUNC('month', subq_13.ds) AS metric_time__month + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine subq_13 + 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_11 + ON + DATE_TRUNC('month', subq_13.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', subq_13.ds) = subq_13.ds + ) subq_15 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month +) subq_19 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql index d3f51452e3..cb53165033 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -29,8 +29,16 @@ 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 DATE_TRUNC('day', 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 @@ -321,11 +329,6 @@ FROM ( ) 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 - ) OR ( - DATE_TRUNC('year', subq_2.metric_time__day) = subq_2.metric_time__day - ) ) subq_4 ) subq_5 GROUP BY diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql index 35be9c4dbc..76767e46c6 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql @@ -25,11 +25,6 @@ FROM ( ) subq_9 ON DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day - WHERE ( - DATE_TRUNC('month', subq_11.ds) = subq_11.ds - ) OR ( - DATE_TRUNC('year', subq_11.ds) = subq_11.ds - ) GROUP BY subq_11.ds , DATE_TRUNC('month', subq_11.ds) diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql index 0c969a8f90..5102273de1 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(isodow FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..ee6af42a72 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) AS metric_time__month + , MAX(subq_9.booking_value) AS booking_value + , MAX(subq_16.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.booking_value + 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 DATE_TRUNC('day', 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 ( + -- Time Spine + SELECT + 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 ( + -- 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 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_15.metric_time__month + , subq_15.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_14.metric_time__month + , COUNT(DISTINCT subq_14.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month'] + SELECT + subq_13.metric_time__month + , subq_13.bookers + FROM ( + -- Constrain Output with WHERE + SELECT + subq_12.metric_time__day + , subq_12.metric_time__month + , subq_12.bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + WHERE metric_time__day = '2020-01-01' + ) subq_13 + ) subq_14 + GROUP BY + subq_14.metric_time__month + ) subq_15 + ) subq_16 + ON + subq_9.metric_time__month = subq_16.metric_time__month + GROUP BY + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) +) subq_17 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..0def7f4cf6 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,62 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) AS metric_time__month + , MAX(subq_27.booking_value) AS booking_value + , MAX(subq_34.bookers) AS bookers + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(booking_value) AS booking_value + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_21.ds AS metric_time__day + , DATE_TRUNC('month', subq_21.ds) AS metric_time__month + , bookings_source_src_28000.booking_value AS booking_value + FROM ***************************.mf_time_spine subq_21 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + subq_21.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + ) subq_23 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_27 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookers', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , COUNT(DISTINCT bookers) AS bookers + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , guest_id AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_30 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_34 + ON + subq_27.metric_time__month = subq_34.metric_time__month + GROUP BY + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) +) subq_35 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql index 8ea23101e2..aabbfd61cc 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql @@ -37,8 +37,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql index 49f6b12f7c..d4128818f7 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(isodow FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql index ad4182373a..b17e12fe70 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 8e8f2d15e5..62ea44b0ec 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -256,6 +256,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql index c913c089ee..63fb598198 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt index 02ed088335..3439f21203 100644 --- a/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt @@ -1,3 +1,63 @@ - metric_time__day metric_time__month metric_time__year bookings_at_start_of_month -0 2019-12-01 2019-12-01 2019-01-01 1 -1 2020-01-01 2020-01-01 2020-01-01 5 + metric_time__day metric_time__month metric_time__year bookings_at_start_of_month +0 2019-12-02 2019-12-01 2019-01-01 1 +1 2019-12-07 2019-12-01 2019-01-01 1 +2 2019-12-24 2019-12-01 2019-01-01 1 +3 2020-01-08 2020-01-01 2020-01-01 5 +4 2020-01-26 2020-01-01 2020-01-01 5 +5 2019-12-18 2019-12-01 2019-01-01 1 +6 2019-12-19 2019-12-01 2019-01-01 1 +7 2019-12-20 2019-12-01 2019-01-01 1 +8 2020-01-06 2020-01-01 2020-01-01 5 +9 2020-01-25 2020-01-01 2020-01-01 5 +10 2019-12-22 2019-12-01 2019-01-01 1 +11 2019-12-23 2019-12-01 2019-01-01 1 +12 2019-12-26 2019-12-01 2019-01-01 1 +13 2019-12-30 2019-12-01 2019-01-01 1 +14 2019-12-31 2019-12-01 2019-01-01 1 +15 2020-01-04 2020-01-01 2020-01-01 5 +16 2020-01-11 2020-01-01 2020-01-01 5 +17 2020-01-14 2020-01-01 2020-01-01 5 +18 2020-01-15 2020-01-01 2020-01-01 5 +19 2020-01-16 2020-01-01 2020-01-01 5 +20 2020-01-22 2020-01-01 2020-01-01 5 +21 2019-12-03 2019-12-01 2019-01-01 1 +22 2019-12-13 2019-12-01 2019-01-01 1 +23 2019-12-14 2019-12-01 2019-01-01 1 +24 2019-12-15 2019-12-01 2019-01-01 1 +25 2019-12-27 2019-12-01 2019-01-01 1 +26 2020-01-03 2020-01-01 2020-01-01 5 +27 2019-12-25 2019-12-01 2019-01-01 1 +28 2020-01-05 2020-01-01 2020-01-01 5 +29 2020-01-13 2020-01-01 2020-01-01 5 +30 2020-01-19 2020-01-01 2020-01-01 5 +31 2020-01-27 2020-01-01 2020-01-01 5 +32 2019-12-01 2019-12-01 2019-01-01 1 +33 2019-12-08 2019-12-01 2019-01-01 1 +34 2019-12-11 2019-12-01 2019-01-01 1 +35 2019-12-21 2019-12-01 2019-01-01 1 +36 2020-01-07 2020-01-01 2020-01-01 5 +37 2020-01-09 2020-01-01 2020-01-01 5 +38 2020-01-18 2020-01-01 2020-01-01 5 +39 2020-01-21 2020-01-01 2020-01-01 5 +40 2020-01-24 2020-01-01 2020-01-01 5 +41 2020-01-29 2020-01-01 2020-01-01 5 +42 2020-01-30 2020-01-01 2020-01-01 5 +43 2020-01-31 2020-01-01 2020-01-01 5 +44 2019-12-06 2019-12-01 2019-01-01 1 +45 2019-12-09 2019-12-01 2019-01-01 1 +46 2019-12-12 2019-12-01 2019-01-01 1 +47 2019-12-16 2019-12-01 2019-01-01 1 +48 2019-12-17 2019-12-01 2019-01-01 1 +49 2020-01-01 2020-01-01 2020-01-01 5 +50 2020-01-02 2020-01-01 2020-01-01 5 +51 2020-01-10 2020-01-01 2020-01-01 5 +52 2020-01-17 2020-01-01 2020-01-01 5 +53 2020-01-20 2020-01-01 2020-01-01 5 +54 2020-01-28 2020-01-01 2020-01-01 5 +55 2019-12-04 2019-12-01 2019-01-01 1 +56 2019-12-05 2019-12-01 2019-01-01 1 +57 2019-12-10 2019-12-01 2019-01-01 1 +58 2019-12-28 2019-12-01 2019-01-01 1 +59 2019-12-29 2019-12-01 2019-01-01 1 +60 2020-01-12 2020-01-01 2020-01-01 5 +61 2020-01-23 2020-01-01 2020-01-01 5 From f4c9abd344e5a9fda0d9839be9ce33a0123b9ef7 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 27 Feb 2024 19:09:28 -0800 Subject: [PATCH 5/8] Add order_by to output tests to ensure consistency --- metricflow/test/integration/query_output/test_offset_metrics.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metricflow/test/integration/query_output/test_offset_metrics.py b/metricflow/test/integration/query_output/test_offset_metrics.py index 84ad816e26..fc0f445cd2 100644 --- a/metricflow/test/integration/query_output/test_offset_metrics.py +++ b/metricflow/test/integration/query_output/test_offset_metrics.py @@ -21,6 +21,7 @@ def test_offset_to_grain_with_single_granularity( # noqa: D MetricFlowQueryRequest.create_with_random_request_id( metric_names=["bookings_at_start_of_month"], group_by_names=["metric_time__day"], + order_by_names=["metric_time__day"], ) ) assert query_result.result_df is not None, "Unexpected empty result." @@ -45,6 +46,7 @@ def test_offset_to_grain_with_multiple_granularities( # noqa: D MetricFlowQueryRequest.create_with_random_request_id( metric_names=["bookings_at_start_of_month"], group_by_names=["metric_time__day", "metric_time__month", "metric_time__year"], + order_by_names=["metric_time__day", "metric_time__month", "metric_time__year"], ) ) assert query_result.result_df is not None, "Unexpected empty result." From 3f7d8164e09b0ec8d3c283e3509b8d4f6fd3956c Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Tue, 27 Feb 2024 21:38:24 -0800 Subject: [PATCH 6/8] Update SQL engine snapshots --- ...set_metric_with_time_constraint__plan0.sql | 10 + ...nth_dimension_and_offset_window__plan0.sql | 5 + ...ved_metric_with_offset_to_grain__plan0.sql | 10 + ...offset_to_grain_and_granularity__plan0.sql | 12 +- ...rived_metric_with_offset_window__plan0.sql | 10 + ...h_offset_window_and_granularity__plan0.sql | 12 +- ...fset_window_and_offset_to_grain__plan0.sql | 20 + ...offset_to_grain_and_granularity__plan0.sql | 24 +- ...h_offset_window_and_time_filter__plan0.sql | 10 + ...erived_offset_cumulative_metric__plan0.sql | 10 + ...offset_metric_with_agg_time_dim__plan0.sql | 10 + ...et_metric_with_one_input_metric__plan0.sql | 10 + ...d_where_constraint_not_selected__plan0.sql | 10 + .../BigQuery/test_nested_offsets__plan0.sql | 10 + ...ed_offsets_with_time_constraint__plan0.sql | 10 + ...d_offsets_with_where_constraint__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 345 +++++++++++ ...fferent_granularities__plan0_optimized.sql | 36 ++ ...n_metric_multiple_granularities__plan0.sql | 339 ++++++++++ ...ultiple_granularities__plan0_optimized.sql | 32 + ...fset_to_grain_with_agg_time_dim__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 585 ++++++++++++++++++ ...fferent_granularities__plan0_optimized.sql | 62 ++ ...w_metric_multiple_granularities__plan0.sql | 583 +++++++++++++++++ ...ultiple_granularities__plan0_optimized.sql | 64 ++ ...offset_window_with_agg_time_dim__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...nth_dimension_and_offset_window__plan0.sql | 5 + ...ved_metric_with_offset_to_grain__plan0.sql | 10 + ...offset_to_grain_and_granularity__plan0.sql | 12 +- ...rived_metric_with_offset_window__plan0.sql | 10 + ...h_offset_window_and_granularity__plan0.sql | 12 +- ...fset_window_and_offset_to_grain__plan0.sql | 20 + ...offset_to_grain_and_granularity__plan0.sql | 24 +- ...h_offset_window_and_time_filter__plan0.sql | 10 + ...erived_offset_cumulative_metric__plan0.sql | 10 + ...offset_metric_with_agg_time_dim__plan0.sql | 10 + ...et_metric_with_one_input_metric__plan0.sql | 10 + ...d_where_constraint_not_selected__plan0.sql | 10 + .../Databricks/test_nested_offsets__plan0.sql | 10 + ...ed_offsets_with_time_constraint__plan0.sql | 10 + ...d_offsets_with_where_constraint__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 345 +++++++++++ ...fferent_granularities__plan0_optimized.sql | 36 ++ ...n_metric_multiple_granularities__plan0.sql | 339 ++++++++++ ...ultiple_granularities__plan0_optimized.sql | 32 + ...fset_to_grain_with_agg_time_dim__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 585 ++++++++++++++++++ ...fferent_granularities__plan0_optimized.sql | 62 ++ ...w_metric_multiple_granularities__plan0.sql | 583 +++++++++++++++++ ...ultiple_granularities__plan0_optimized.sql | 64 ++ ...offset_window_with_agg_time_dim__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...nth_dimension_and_offset_window__plan0.sql | 5 + ...ved_metric_with_offset_to_grain__plan0.sql | 10 + ...offset_to_grain_and_granularity__plan0.sql | 12 +- ...rived_metric_with_offset_window__plan0.sql | 10 + ...h_offset_window_and_granularity__plan0.sql | 12 +- ...fset_window_and_offset_to_grain__plan0.sql | 20 + ...offset_to_grain_and_granularity__plan0.sql | 24 +- ...h_offset_window_and_time_filter__plan0.sql | 10 + ...erived_offset_cumulative_metric__plan0.sql | 10 + ...offset_metric_with_agg_time_dim__plan0.sql | 10 + ...et_metric_with_one_input_metric__plan0.sql | 10 + ...d_where_constraint_not_selected__plan0.sql | 10 + .../Postgres/test_nested_offsets__plan0.sql | 10 + ...ed_offsets_with_time_constraint__plan0.sql | 10 + ...d_offsets_with_where_constraint__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 345 +++++++++++ ...fferent_granularities__plan0_optimized.sql | 36 ++ ...n_metric_multiple_granularities__plan0.sql | 339 ++++++++++ ...ultiple_granularities__plan0_optimized.sql | 32 + ...fset_to_grain_with_agg_time_dim__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 585 ++++++++++++++++++ ...fferent_granularities__plan0_optimized.sql | 62 ++ ...w_metric_multiple_granularities__plan0.sql | 583 +++++++++++++++++ ...ultiple_granularities__plan0_optimized.sql | 64 ++ ...offset_window_with_agg_time_dim__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...nth_dimension_and_offset_window__plan0.sql | 5 + ...ved_metric_with_offset_to_grain__plan0.sql | 10 + ...offset_to_grain_and_granularity__plan0.sql | 12 +- ...rived_metric_with_offset_window__plan0.sql | 10 + ...h_offset_window_and_granularity__plan0.sql | 12 +- ...fset_window_and_offset_to_grain__plan0.sql | 20 + ...offset_to_grain_and_granularity__plan0.sql | 24 +- ...h_offset_window_and_time_filter__plan0.sql | 10 + ...erived_offset_cumulative_metric__plan0.sql | 10 + ...offset_metric_with_agg_time_dim__plan0.sql | 10 + ...et_metric_with_one_input_metric__plan0.sql | 10 + ...d_where_constraint_not_selected__plan0.sql | 10 + .../Redshift/test_nested_offsets__plan0.sql | 10 + ...ed_offsets_with_time_constraint__plan0.sql | 10 + ...d_offsets_with_where_constraint__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 345 +++++++++++ ...fferent_granularities__plan0_optimized.sql | 36 ++ ...n_metric_multiple_granularities__plan0.sql | 339 ++++++++++ ...ultiple_granularities__plan0_optimized.sql | 32 + ...fset_to_grain_with_agg_time_dim__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 585 ++++++++++++++++++ ...fferent_granularities__plan0_optimized.sql | 62 ++ ...w_metric_multiple_granularities__plan0.sql | 583 +++++++++++++++++ ...ultiple_granularities__plan0_optimized.sql | 64 ++ ...offset_window_with_agg_time_dim__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...nth_dimension_and_offset_window__plan0.sql | 5 + ...ved_metric_with_offset_to_grain__plan0.sql | 10 + ...offset_to_grain_and_granularity__plan0.sql | 12 +- ...rived_metric_with_offset_window__plan0.sql | 10 + ...h_offset_window_and_granularity__plan0.sql | 12 +- ...fset_window_and_offset_to_grain__plan0.sql | 20 + ...offset_to_grain_and_granularity__plan0.sql | 24 +- ...h_offset_window_and_time_filter__plan0.sql | 10 + ...erived_offset_cumulative_metric__plan0.sql | 10 + ...offset_metric_with_agg_time_dim__plan0.sql | 10 + ...et_metric_with_one_input_metric__plan0.sql | 10 + ...d_where_constraint_not_selected__plan0.sql | 10 + .../Snowflake/test_nested_offsets__plan0.sql | 10 + ...ed_offsets_with_time_constraint__plan0.sql | 10 + ...d_offsets_with_where_constraint__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 345 +++++++++++ ...fferent_granularities__plan0_optimized.sql | 36 ++ ...n_metric_multiple_granularities__plan0.sql | 339 ++++++++++ ...ultiple_granularities__plan0_optimized.sql | 32 + ...fset_to_grain_with_agg_time_dim__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 585 ++++++++++++++++++ ...fferent_granularities__plan0_optimized.sql | 62 ++ ...w_metric_multiple_granularities__plan0.sql | 583 +++++++++++++++++ ...ultiple_granularities__plan0_optimized.sql | 64 ++ ...offset_window_with_agg_time_dim__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...nth_dimension_and_offset_window__plan0.sql | 5 + ...ved_metric_with_offset_to_grain__plan0.sql | 10 + ...offset_to_grain_and_granularity__plan0.sql | 12 +- ...rived_metric_with_offset_window__plan0.sql | 10 + ...h_offset_window_and_granularity__plan0.sql | 12 +- ...fset_window_and_offset_to_grain__plan0.sql | 20 + ...offset_to_grain_and_granularity__plan0.sql | 24 +- ...h_offset_window_and_time_filter__plan0.sql | 10 + ...erived_offset_cumulative_metric__plan0.sql | 10 + ...offset_metric_with_agg_time_dim__plan0.sql | 10 + ...et_metric_with_one_input_metric__plan0.sql | 10 + ...d_where_constraint_not_selected__plan0.sql | 10 + .../Trino/test_nested_offsets__plan0.sql | 10 + ...ed_offsets_with_time_constraint__plan0.sql | 10 + ...d_offsets_with_where_constraint__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 345 +++++++++++ ...fferent_granularities__plan0_optimized.sql | 36 ++ ...n_metric_multiple_granularities__plan0.sql | 339 ++++++++++ ...ultiple_granularities__plan0_optimized.sql | 32 + ...fset_to_grain_with_agg_time_dim__plan0.sql | 10 + ...ry_have_different_granularities__plan0.sql | 585 ++++++++++++++++++ ...fferent_granularities__plan0_optimized.sql | 62 ++ ...w_metric_multiple_granularities__plan0.sql | 583 +++++++++++++++++ ...ultiple_granularities__plan0_optimized.sql | 64 ++ ...offset_window_with_agg_time_dim__plan0.sql | 10 + ...set_metric_with_time_constraint__plan0.sql | 10 + ...fill_nulls_for_one_input_metric__plan0.sql | 10 + ...fill_nulls_for_one_input_metric__plan0.sql | 10 + ...fill_nulls_for_one_input_metric__plan0.sql | 10 + ...fill_nulls_for_one_input_metric__plan0.sql | 10 + ...fill_nulls_for_one_input_metric__plan0.sql | 10 + ...fill_nulls_for_one_input_metric__plan0.sql | 10 + ...st_offset_window_with_date_part__plan0.sql | 12 +- ...st_offset_window_with_date_part__plan0.sql | 12 +- ...st_offset_window_with_date_part__plan0.sql | 12 +- ...st_offset_window_with_date_part__plan0.sql | 12 +- ...st_offset_window_with_date_part__plan0.sql | 12 +- ...st_offset_window_with_date_part__plan0.sql | 12 +- ...h_multiple_granularities__query_output.txt | 63 ++ ..._with_single_granularity__query_output.txt | 63 ++ ...h_multiple_granularities__query_output.txt | 63 ++ ..._with_single_granularity__query_output.txt | 63 ++ ...h_multiple_granularities__query_output.txt | 124 ++-- ..._with_single_granularity__query_output.txt | 124 ++-- ...h_multiple_granularities__query_output.txt | 63 ++ ..._with_single_granularity__query_output.txt | 63 ++ ...h_multiple_granularities__query_output.txt | 63 ++ ..._with_single_granularity__query_output.txt | 63 ++ ...h_multiple_granularities__query_output.txt | 63 ++ ..._with_single_granularity__query_output.txt | 63 ++ ...h_multiple_granularities__query_output.txt | 63 ++ ..._with_single_granularity__query_output.txt | 63 ++ 188 files changed, 14536 insertions(+), 154 deletions(-) create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql create mode 100644 metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/BigQuery/test_offset_to_grain_with_multiple_granularities__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/BigQuery/test_offset_to_grain_with_single_granularity__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/Databricks/test_offset_to_grain_with_multiple_granularities__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/Databricks/test_offset_to_grain_with_single_granularity__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/Postgres/test_offset_to_grain_with_multiple_granularities__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/Postgres/test_offset_to_grain_with_single_granularity__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/Redshift/test_offset_to_grain_with_multiple_granularities__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/Redshift/test_offset_to_grain_with_single_granularity__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/Snowflake/test_offset_to_grain_with_multiple_granularities__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/Snowflake/test_offset_to_grain_with_single_granularity__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/Trino/test_offset_to_grain_with_multiple_granularities__query_output.txt create mode 100644 metricflow/test/snapshots/test_offset_metrics.py/str/Trino/test_offset_to_grain_with_single_granularity__query_output.txt diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 5116906208..d2c5bfadcf 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -26,6 +26,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_5.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_5.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_5.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_5.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_5.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , IF(EXTRACT(dayofweek FROM subq_5.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_5.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 0de5b54144..8fe6ff6836 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -21,6 +21,11 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__month AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__month, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__month, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__month, month)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month , subq_1.monthly_ds__quarter AS monthly_ds__quarter , subq_1.monthly_ds__year AS monthly_ds__year diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql index 723c407077..8bdb432802 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_7.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_7.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_7.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_7.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_7.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , IF(EXTRACT(dayofweek FROM subq_7.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_7.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index c46e8b8282..5e4c76815d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC(subq_7.metric_time__day, isoweek) AS metric_time__week + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_7.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_7.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_7.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_7.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_7.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , IF(EXTRACT(dayofweek FROM subq_7.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_7.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql index 015983942d..8a428ddd21 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_7.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_7.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_7.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_7.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_7.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , IF(EXTRACT(dayofweek FROM subq_7.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_7.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql index f224a6aa82..72b321ab94 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC(subq_7.metric_time__day, quarter) AS metric_time__quarter + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_7.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_7.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_7.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_7.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_7.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , IF(EXTRACT(dayofweek FROM subq_7.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_7.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index dd892d41a2..f2e3424dd7 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -27,6 +27,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 @@ -342,6 +352,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_10.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_10.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_10.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_10.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_10.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , IF(EXTRACT(dayofweek FROM subq_10.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_10.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 6b2b98c085..f667f7966a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -26,7 +26,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 @@ -342,7 +352,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC(subq_10.metric_time__day, year) AS metric_time__year + subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_10.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_10.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_10.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_10.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_10.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , IF(EXTRACT(dayofweek FROM subq_10.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_10.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 28e9947508..ee0e0e7396 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -254,6 +254,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_8.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_8.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_8.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_8.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_8.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_8.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_8.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_8.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql index 6b45b43b8f..2dc0542e6b 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_5.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_5.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_5.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_5.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_5.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , IF(EXTRACT(dayofweek FROM subq_5.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_5.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 0728613455..e629ec0111 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -27,6 +27,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.booking__ds__day AS booking__ds__day + , DATE_TRUNC(subq_2.booking__ds__day, isoweek) AS booking__ds__week + , DATE_TRUNC(subq_2.booking__ds__day, month) AS booking__ds__month + , DATE_TRUNC(subq_2.booking__ds__day, quarter) AS booking__ds__quarter + , DATE_TRUNC(subq_2.booking__ds__day, year) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.booking__ds__day, day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM subq_2.booking__ds__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.booking__ds__day) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM subq_2.booking__ds__day) AS booking__ds__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql index 6c7876d0ee..dea5b0b5b2 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 4bc0ed2b1e..df694e4e33 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -53,6 +53,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql index 879d401fa4..83512db0c0 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql @@ -37,6 +37,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql index ef179c4a89..15146a1d59 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql @@ -38,6 +38,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql index 2be549986f..1de9e06484 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql @@ -42,6 +42,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..ef490bc65d --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,345 @@ +-- Compute Metrics via Expressions +SELECT + subq_9.metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 ( + -- Time Spine + SELECT + 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 ( + -- 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(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATE_TRUNC(subq_2.metric_time__day, month) = subq_1.metric_time__day + WHERE DATE_TRUNC(subq_2.metric_time__day, month) = subq_2.metric_time__day + ) subq_4 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + metric_time__month + ) subq_8 +) subq_9 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..d5542de120 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,36 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(bookings) AS bookings_start_of_month + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_13.ds AS metric_time__day + , DATE_TRUNC(subq_13.ds, month) AS metric_time__month + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine subq_13 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC(ds, day) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_11 + ON + DATE_TRUNC(subq_13.ds, month) = subq_11.metric_time__day + WHERE DATE_TRUNC(subq_13.ds, month) = subq_13.ds + ) subq_15 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month +) subq_19 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..fad7675aa8 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -0,0 +1,339 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.bookings + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 ( + -- Time Spine + SELECT + 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 ( + -- 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(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATE_TRUNC(subq_2.metric_time__day, month) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + metric_time__day + , metric_time__month + , metric_time__year + ) subq_6 +) subq_7 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..ba2d0ffcfc --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,32 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_11.ds AS metric_time__day + , DATE_TRUNC(subq_11.ds, month) AS metric_time__month + , DATE_TRUNC(subq_11.ds, year) AS metric_time__year + , SUM(subq_9.bookings) AS bookings_start_of_month + FROM ***************************.mf_time_spine subq_11 + INNER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + SELECT + DATE_TRUNC(ds, day) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_9 + ON + DATE_TRUNC(subq_11.ds, month) = subq_9.metric_time__day + GROUP BY + metric_time__day + , metric_time__month + , metric_time__year +) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql index a3387ad17f..b168018fc0 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC(subq_7.booking__ds__day, isoweek) AS booking__ds__week + , DATE_TRUNC(subq_7.booking__ds__day, month) AS booking__ds__month + , DATE_TRUNC(subq_7.booking__ds__day, quarter) AS booking__ds__quarter + , DATE_TRUNC(subq_7.booking__ds__day, year) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC(subq_7.booking__ds__day, day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM subq_7.booking__ds__day) = 1, 7, EXTRACT(dayofweek FROM subq_7.booking__ds__day) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..61ddae66ea --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) AS metric_time__month + , MAX(subq_9.booking_value) AS booking_value + , MAX(subq_16.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.booking_value + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 ( + -- Time Spine + SELECT + 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 ( + -- 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(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 1 week) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + metric_time__month + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_15.metric_time__month + , subq_15.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_14.metric_time__month + , COUNT(DISTINCT subq_14.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month'] + SELECT + subq_13.metric_time__month + , subq_13.bookers + FROM ( + -- Constrain Output with WHERE + SELECT + subq_12.metric_time__day + , subq_12.metric_time__month + , subq_12.bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + WHERE metric_time__day = '2020-01-01' + ) subq_13 + ) subq_14 + GROUP BY + metric_time__month + ) subq_15 + ) subq_16 + ON + subq_9.metric_time__month = subq_16.metric_time__month + GROUP BY + metric_time__month +) subq_17 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..a0c623e6c9 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,62 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) AS metric_time__month + , MAX(subq_27.booking_value) AS booking_value + , MAX(subq_34.bookers) AS bookers + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(booking_value) AS booking_value + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_21.ds AS metric_time__day + , DATE_TRUNC(subq_21.ds, month) AS metric_time__month + , bookings_source_src_28000.booking_value AS booking_value + FROM ***************************.mf_time_spine subq_21 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + DATE_SUB(CAST(subq_21.ds AS DATETIME), INTERVAL 1 week) = DATE_TRUNC(bookings_source_src_28000.ds, day) + ) subq_23 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_27 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookers', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , COUNT(DISTINCT bookers) AS bookers + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + DATE_TRUNC(ds, day) AS metric_time__day + , DATE_TRUNC(ds, month) AS metric_time__month + , guest_id AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_30 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_34 + ON + subq_27.metric_time__month = subq_34.metric_time__month + GROUP BY + metric_time__month +) subq_35 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..8dcf125ff4 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql @@ -0,0 +1,583 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , subq_13.metric_time__month + , subq_13.metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) AS metric_time__month + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) AS metric_time__year + , MAX(subq_7.booking_value) AS booking_value + , MAX(subq_12.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.booking_value + FROM ( + -- Join to Time Spine Dataset + SELECT + subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 ( + -- Time Spine + SELECT + 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 ( + -- 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(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATE_SUB(CAST(subq_2.metric_time__day AS DATETIME), INTERVAL 1 week) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + metric_time__day + , metric_time__month + , metric_time__year + ) subq_6 + ) subq_7 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + , subq_11.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + , COUNT(DISTINCT subq_10.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_9.metric_time__day + , subq_9.metric_time__month + , subq_9.metric_time__year + , subq_9.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.ds_partitioned__day + , subq_8.ds_partitioned__week + , subq_8.ds_partitioned__month + , subq_8.ds_partitioned__quarter + , subq_8.ds_partitioned__year + , subq_8.ds_partitioned__extract_year + , subq_8.ds_partitioned__extract_quarter + , subq_8.ds_partitioned__extract_month + , subq_8.ds_partitioned__extract_day + , subq_8.ds_partitioned__extract_dow + , subq_8.ds_partitioned__extract_doy + , subq_8.paid_at__day + , subq_8.paid_at__week + , subq_8.paid_at__month + , subq_8.paid_at__quarter + , subq_8.paid_at__year + , subq_8.paid_at__extract_year + , subq_8.paid_at__extract_quarter + , subq_8.paid_at__extract_month + , subq_8.paid_at__extract_day + , subq_8.paid_at__extract_dow + , subq_8.paid_at__extract_doy + , subq_8.booking__ds__day + , subq_8.booking__ds__week + , subq_8.booking__ds__month + , subq_8.booking__ds__quarter + , subq_8.booking__ds__year + , subq_8.booking__ds__extract_year + , subq_8.booking__ds__extract_quarter + , subq_8.booking__ds__extract_month + , subq_8.booking__ds__extract_day + , subq_8.booking__ds__extract_dow + , subq_8.booking__ds__extract_doy + , subq_8.booking__ds_partitioned__day + , subq_8.booking__ds_partitioned__week + , subq_8.booking__ds_partitioned__month + , subq_8.booking__ds_partitioned__quarter + , subq_8.booking__ds_partitioned__year + , subq_8.booking__ds_partitioned__extract_year + , subq_8.booking__ds_partitioned__extract_quarter + , subq_8.booking__ds_partitioned__extract_month + , subq_8.booking__ds_partitioned__extract_day + , subq_8.booking__ds_partitioned__extract_dow + , subq_8.booking__ds_partitioned__extract_doy + , subq_8.booking__paid_at__day + , subq_8.booking__paid_at__week + , subq_8.booking__paid_at__month + , subq_8.booking__paid_at__quarter + , subq_8.booking__paid_at__year + , subq_8.booking__paid_at__extract_year + , subq_8.booking__paid_at__extract_quarter + , subq_8.booking__paid_at__extract_month + , subq_8.booking__paid_at__extract_day + , subq_8.booking__paid_at__extract_dow + , subq_8.booking__paid_at__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy + , subq_8.listing + , subq_8.guest + , subq_8.host + , subq_8.booking__listing + , subq_8.booking__guest + , subq_8.booking__host + , subq_8.is_instant + , subq_8.booking__is_instant + , subq_8.bookings + , subq_8.instant_bookings + , subq_8.booking_value + , subq_8.max_booking_value + , subq_8.min_booking_value + , subq_8.bookers + , subq_8.average_booking_value + , subq_8.referred_bookings + , subq_8.median_booking_value + , subq_8.booking_value_p99 + , subq_8.discrete_booking_value_p99 + , subq_8.approximate_continuous_booking_value_p99 + , subq_8.approximate_discrete_booking_value_p99 + 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(bookings_source_src_28000.ds, day) AS ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC(bookings_source_src_28000.ds, day) AS booking__ds__day + , DATE_TRUNC(bookings_source_src_28000.ds, isoweek) AS booking__ds__week + , DATE_TRUNC(bookings_source_src_28000.ds, month) AS booking__ds__month + , DATE_TRUNC(bookings_source_src_28000.ds, quarter) AS booking__ds__quarter + , DATE_TRUNC(bookings_source_src_28000.ds, year) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, day) AS booking__ds_partitioned__day + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, isoweek) AS booking__ds_partitioned__week + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, month) AS booking__ds_partitioned__month + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, quarter) AS booking__ds_partitioned__quarter + , DATE_TRUNC(bookings_source_src_28000.ds_partitioned, year) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.ds_partitioned) - 1) AS booking__ds_partitioned__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC(bookings_source_src_28000.paid_at, day) AS booking__paid_at__day + , DATE_TRUNC(bookings_source_src_28000.paid_at, isoweek) AS booking__paid_at__week + , DATE_TRUNC(bookings_source_src_28000.paid_at, month) AS booking__paid_at__month + , DATE_TRUNC(bookings_source_src_28000.paid_at, quarter) AS booking__paid_at__quarter + , DATE_TRUNC(bookings_source_src_28000.paid_at, year) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , IF(EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) = 1, 7, EXTRACT(dayofweek FROM bookings_source_src_28000.paid_at) - 1) AS booking__paid_at__extract_dow + , EXTRACT(dayofyear FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_8 + ) subq_9 + ) subq_10 + GROUP BY + metric_time__day + , metric_time__month + , metric_time__year + ) subq_11 + ) subq_12 + ON + ( + subq_7.metric_time__day = subq_12.metric_time__day + ) AND ( + subq_7.metric_time__month = subq_12.metric_time__month + ) AND ( + subq_7.metric_time__year = subq_12.metric_time__year + ) + GROUP BY + metric_time__day + , metric_time__month + , metric_time__year +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..9c7267c179 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,64 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) AS metric_time__day + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) AS metric_time__month + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) AS metric_time__year + , MAX(subq_21.booking_value) AS booking_value + , MAX(subq_26.bookers) AS bookers + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_17.ds AS metric_time__day + , DATE_TRUNC(subq_17.ds, month) AS metric_time__month + , DATE_TRUNC(subq_17.ds, year) AS metric_time__year + , SUM(bookings_source_src_28000.booking_value) AS booking_value + FROM ***************************.mf_time_spine subq_17 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + DATE_SUB(CAST(subq_17.ds AS DATETIME), INTERVAL 1 week) = DATE_TRUNC(bookings_source_src_28000.ds, day) + GROUP BY + metric_time__day + , metric_time__month + , metric_time__year + ) subq_21 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC(ds, day) AS metric_time__day + , DATE_TRUNC(ds, month) AS metric_time__month + , DATE_TRUNC(ds, year) AS metric_time__year + , COUNT(DISTINCT guest_id) AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + metric_time__day + , metric_time__month + , metric_time__year + ) subq_26 + ON + ( + subq_21.metric_time__day = subq_26.metric_time__day + ) AND ( + subq_21.metric_time__month = subq_26.metric_time__month + ) AND ( + subq_21.metric_time__year = subq_26.metric_time__year + ) + GROUP BY + metric_time__day + , metric_time__month + , metric_time__year +) subq_27 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql index e5f2f4b27c..463df5d0ce 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC(subq_7.booking__ds__day, isoweek) AS booking__ds__week + , DATE_TRUNC(subq_7.booking__ds__day, month) AS booking__ds__month + , DATE_TRUNC(subq_7.booking__ds__day, quarter) AS booking__ds__quarter + , DATE_TRUNC(subq_7.booking__ds__day, year) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC(subq_7.booking__ds__day, day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , IF(EXTRACT(dayofweek FROM subq_7.booking__ds__day) = 1, 7, EXTRACT(dayofweek FROM subq_7.booking__ds__day) - 1) AS booking__ds__extract_dow + , EXTRACT(dayofyear FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql index f2a648fcd3..7d12e9fb15 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_2.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, 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 + , IF(EXTRACT(dayofweek FROM subq_2.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_2.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 811ac72291..1b435f4495 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -26,6 +26,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 72735021e2..2b3e35d6a0 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -21,6 +21,11 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__month AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month , subq_1.monthly_ds__quarter AS monthly_ds__quarter , subq_1.monthly_ds__year AS monthly_ds__year diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql index ac0e57b861..8ad6f65544 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 682e95a00e..348e92eae2 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql index ecebbf37b9..02af4345b9 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 4f5270f9fc..1e89bbe0ed 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 42025e449a..536bc19f16 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -27,6 +27,16 @@ 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 @@ -342,6 +352,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 7c4658a882..009d8fd594 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -26,7 +26,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 @@ -342,7 +352,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 34b0d287f5..2828f54a58 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -254,6 +254,16 @@ FROM ( -- Join to Time Spine Dataset 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql index 3366878673..a614160904 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql index c72bf28543..f49fdea2fa 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -27,6 +27,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_2.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_2.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_2.booking__ds__day) AS booking__ds__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql index 66d544ac86..c4ad2c66cb 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 7ca829d97b..cc86591ea4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -53,6 +53,16 @@ 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql index c25499297b..ce28a61bf5 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql @@ -37,6 +37,16 @@ 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql index 446c356002..8c6d930be4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql @@ -38,6 +38,16 @@ 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql index e367be6b8f..dc573f5598 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql @@ -42,6 +42,16 @@ 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..9be1a0795e --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,345 @@ +-- Compute Metrics via Expressions +SELECT + subq_9.metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.bookings + 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + 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 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 +) subq_9 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..bfd3b8fbce --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,36 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(bookings) AS bookings_start_of_month + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_13.ds AS metric_time__day + , DATE_TRUNC('month', subq_13.ds) AS metric_time__month + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine subq_13 + 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_11 + ON + DATE_TRUNC('month', subq_13.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', subq_13.ds) = subq_13.ds + ) subq_15 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month +) subq_19 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..77d4118a1d --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -0,0 +1,339 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.bookings + 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 +) subq_7 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..76767e46c6 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,32 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_11.ds AS metric_time__day + , DATE_TRUNC('month', subq_11.ds) AS metric_time__month + , DATE_TRUNC('year', subq_11.ds) AS metric_time__year + , SUM(subq_9.bookings) AS bookings_start_of_month + FROM ***************************.mf_time_spine subq_11 + 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_9 + ON + DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + GROUP BY + subq_11.ds + , DATE_TRUNC('month', subq_11.ds) + , DATE_TRUNC('year', subq_11.ds) +) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql index a66b9ee824..ecd2c408b3 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..bef875a0de --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) AS metric_time__month + , MAX(subq_9.booking_value) AS booking_value + , MAX(subq_16.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.booking_value + 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_15.metric_time__month + , subq_15.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_14.metric_time__month + , COUNT(DISTINCT subq_14.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month'] + SELECT + subq_13.metric_time__month + , subq_13.bookers + FROM ( + -- Constrain Output with WHERE + SELECT + subq_12.metric_time__day + , subq_12.metric_time__month + , subq_12.bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + WHERE metric_time__day = '2020-01-01' + ) subq_13 + ) subq_14 + GROUP BY + subq_14.metric_time__month + ) subq_15 + ) subq_16 + ON + subq_9.metric_time__month = subq_16.metric_time__month + GROUP BY + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) +) subq_17 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..da44e813f4 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,62 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) AS metric_time__month + , MAX(subq_27.booking_value) AS booking_value + , MAX(subq_34.bookers) AS bookers + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(booking_value) AS booking_value + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_21.ds AS metric_time__day + , DATE_TRUNC('month', subq_21.ds) AS metric_time__month + , bookings_source_src_28000.booking_value AS booking_value + FROM ***************************.mf_time_spine subq_21 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + DATEADD(week, -1, subq_21.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + ) subq_23 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_27 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookers', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , COUNT(DISTINCT bookers) AS bookers + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , guest_id AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_30 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_34 + ON + subq_27.metric_time__month = subq_34.metric_time__month + GROUP BY + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) +) subq_35 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..e882b9666d --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql @@ -0,0 +1,583 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , subq_13.metric_time__month + , subq_13.metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) AS metric_time__month + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) AS metric_time__year + , MAX(subq_7.booking_value) AS booking_value + , MAX(subq_12.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.booking_value + 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 + ) subq_7 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + , subq_11.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + , COUNT(DISTINCT subq_10.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_9.metric_time__day + , subq_9.metric_time__month + , subq_9.metric_time__year + , subq_9.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.ds_partitioned__day + , subq_8.ds_partitioned__week + , subq_8.ds_partitioned__month + , subq_8.ds_partitioned__quarter + , subq_8.ds_partitioned__year + , subq_8.ds_partitioned__extract_year + , subq_8.ds_partitioned__extract_quarter + , subq_8.ds_partitioned__extract_month + , subq_8.ds_partitioned__extract_day + , subq_8.ds_partitioned__extract_dow + , subq_8.ds_partitioned__extract_doy + , subq_8.paid_at__day + , subq_8.paid_at__week + , subq_8.paid_at__month + , subq_8.paid_at__quarter + , subq_8.paid_at__year + , subq_8.paid_at__extract_year + , subq_8.paid_at__extract_quarter + , subq_8.paid_at__extract_month + , subq_8.paid_at__extract_day + , subq_8.paid_at__extract_dow + , subq_8.paid_at__extract_doy + , subq_8.booking__ds__day + , subq_8.booking__ds__week + , subq_8.booking__ds__month + , subq_8.booking__ds__quarter + , subq_8.booking__ds__year + , subq_8.booking__ds__extract_year + , subq_8.booking__ds__extract_quarter + , subq_8.booking__ds__extract_month + , subq_8.booking__ds__extract_day + , subq_8.booking__ds__extract_dow + , subq_8.booking__ds__extract_doy + , subq_8.booking__ds_partitioned__day + , subq_8.booking__ds_partitioned__week + , subq_8.booking__ds_partitioned__month + , subq_8.booking__ds_partitioned__quarter + , subq_8.booking__ds_partitioned__year + , subq_8.booking__ds_partitioned__extract_year + , subq_8.booking__ds_partitioned__extract_quarter + , subq_8.booking__ds_partitioned__extract_month + , subq_8.booking__ds_partitioned__extract_day + , subq_8.booking__ds_partitioned__extract_dow + , subq_8.booking__ds_partitioned__extract_doy + , subq_8.booking__paid_at__day + , subq_8.booking__paid_at__week + , subq_8.booking__paid_at__month + , subq_8.booking__paid_at__quarter + , subq_8.booking__paid_at__year + , subq_8.booking__paid_at__extract_year + , subq_8.booking__paid_at__extract_quarter + , subq_8.booking__paid_at__extract_month + , subq_8.booking__paid_at__extract_day + , subq_8.booking__paid_at__extract_dow + , subq_8.booking__paid_at__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy + , subq_8.listing + , subq_8.guest + , subq_8.host + , subq_8.booking__listing + , subq_8.booking__guest + , subq_8.booking__host + , subq_8.is_instant + , subq_8.booking__is_instant + , subq_8.bookings + , subq_8.instant_bookings + , subq_8.booking_value + , subq_8.max_booking_value + , subq_8.min_booking_value + , subq_8.bookers + , subq_8.average_booking_value + , subq_8.referred_bookings + , subq_8.median_booking_value + , subq_8.booking_value_p99 + , subq_8.discrete_booking_value_p99 + , subq_8.approximate_continuous_booking_value_p99 + , subq_8.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_8 + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + ) subq_11 + ) subq_12 + ON + ( + subq_7.metric_time__day = subq_12.metric_time__day + ) AND ( + subq_7.metric_time__month = subq_12.metric_time__month + ) AND ( + subq_7.metric_time__year = subq_12.metric_time__year + ) + GROUP BY + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..58b1be36eb --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,64 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) AS metric_time__day + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) AS metric_time__month + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) AS metric_time__year + , MAX(subq_21.booking_value) AS booking_value + , MAX(subq_26.bookers) AS bookers + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_17.ds AS metric_time__day + , DATE_TRUNC('month', subq_17.ds) AS metric_time__month + , DATE_TRUNC('year', subq_17.ds) AS metric_time__year + , SUM(bookings_source_src_28000.booking_value) AS booking_value + FROM ***************************.mf_time_spine subq_17 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + GROUP BY + subq_17.ds + , DATE_TRUNC('month', subq_17.ds) + , DATE_TRUNC('year', subq_17.ds) + ) subq_21 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , DATE_TRUNC('year', ds) AS metric_time__year + , COUNT(DISTINCT guest_id) AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + , DATE_TRUNC('month', ds) + , DATE_TRUNC('year', ds) + ) subq_26 + ON + ( + subq_21.metric_time__day = subq_26.metric_time__day + ) AND ( + subq_21.metric_time__month = subq_26.metric_time__month + ) AND ( + subq_21.metric_time__year = subq_26.metric_time__year + ) + GROUP BY + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) +) subq_27 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql index 2d82db179e..000589c8d4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql index 6539ddc435..92d9b8effa 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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(DAYOFWEEK_ISO 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 93d2cbe7ad..b5849bfaef 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -26,6 +26,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 95226e4eb9..0787c597b5 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -21,6 +21,11 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__month AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month , subq_1.monthly_ds__quarter AS monthly_ds__quarter , subq_1.monthly_ds__year AS monthly_ds__year diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql index 36c1caf422..c7ab524c14 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 328247b22e..d1d423597c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql index 063b65c511..60cf8b9286 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 5e6af0c9c1..be4440178a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 314420aafd..c1a78af259 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -27,6 +27,16 @@ 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 DATE_TRUNC('day', 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 @@ -342,6 +352,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 97630c3c85..4366a9cac4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -26,7 +26,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + 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 DATE_TRUNC('day', 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 @@ -342,7 +352,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index cf0e1046ef..b264b7bc30 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -254,6 +254,16 @@ FROM ( -- Join to Time Spine Dataset 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql index 7f54154151..672e3ef336 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 40cd91751a..e74ab5ef61 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -27,6 +27,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_2.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(isodow FROM subq_2.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_2.booking__ds__day) AS booking__ds__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql index dced10c870..0733cbc2d4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index a6ccf08715..5a2dea6036 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -53,6 +53,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql index bc2db4964f..51cdf81e05 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql @@ -37,6 +37,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql index 226858690b..2270ea5b14 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql @@ -38,6 +38,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql index 159920380a..36cd0d136a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql @@ -42,6 +42,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..017e0f1383 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,345 @@ +-- Compute Metrics via Expressions +SELECT + subq_9.metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.bookings + 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 DATE_TRUNC('day', 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 ( + -- Time Spine + SELECT + 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 ( + -- 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 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 +) subq_9 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..bfd3b8fbce --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,36 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(bookings) AS bookings_start_of_month + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_13.ds AS metric_time__day + , DATE_TRUNC('month', subq_13.ds) AS metric_time__month + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine subq_13 + 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_11 + ON + DATE_TRUNC('month', subq_13.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', subq_13.ds) = subq_13.ds + ) subq_15 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month +) subq_19 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..cb53165033 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -0,0 +1,339 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.bookings + 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 DATE_TRUNC('day', 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 ( + -- Time Spine + SELECT + 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 ( + -- 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 + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 +) subq_7 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..76767e46c6 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,32 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_11.ds AS metric_time__day + , DATE_TRUNC('month', subq_11.ds) AS metric_time__month + , DATE_TRUNC('year', subq_11.ds) AS metric_time__year + , SUM(subq_9.bookings) AS bookings_start_of_month + FROM ***************************.mf_time_spine subq_11 + 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_9 + ON + DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + GROUP BY + subq_11.ds + , DATE_TRUNC('month', subq_11.ds) + , DATE_TRUNC('year', subq_11.ds) +) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql index 0c969a8f90..5102273de1 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(isodow FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..a4d00f82aa --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) AS metric_time__month + , MAX(subq_9.booking_value) AS booking_value + , MAX(subq_16.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.booking_value + 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 DATE_TRUNC('day', 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 ( + -- Time Spine + SELECT + 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 ( + -- 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 - MAKE_INTERVAL(weeks => 1) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_15.metric_time__month + , subq_15.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_14.metric_time__month + , COUNT(DISTINCT subq_14.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month'] + SELECT + subq_13.metric_time__month + , subq_13.bookers + FROM ( + -- Constrain Output with WHERE + SELECT + subq_12.metric_time__day + , subq_12.metric_time__month + , subq_12.bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + WHERE metric_time__day = '2020-01-01' + ) subq_13 + ) subq_14 + GROUP BY + subq_14.metric_time__month + ) subq_15 + ) subq_16 + ON + subq_9.metric_time__month = subq_16.metric_time__month + GROUP BY + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) +) subq_17 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..f83880110c --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,62 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) AS metric_time__month + , MAX(subq_27.booking_value) AS booking_value + , MAX(subq_34.bookers) AS bookers + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(booking_value) AS booking_value + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_21.ds AS metric_time__day + , DATE_TRUNC('month', subq_21.ds) AS metric_time__month + , bookings_source_src_28000.booking_value AS booking_value + FROM ***************************.mf_time_spine subq_21 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + subq_21.ds - MAKE_INTERVAL(weeks => 1) = DATE_TRUNC('day', bookings_source_src_28000.ds) + ) subq_23 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_27 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookers', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , COUNT(DISTINCT bookers) AS bookers + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , guest_id AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_30 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_34 + ON + subq_27.metric_time__month = subq_34.metric_time__month + GROUP BY + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) +) subq_35 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..b575040541 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql @@ -0,0 +1,583 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , subq_13.metric_time__month + , subq_13.metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) AS metric_time__month + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) AS metric_time__year + , MAX(subq_7.booking_value) AS booking_value + , MAX(subq_12.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.booking_value + 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 DATE_TRUNC('day', 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 ( + -- Time Spine + SELECT + 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 ( + -- 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 - MAKE_INTERVAL(weeks => 1) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 + ) subq_7 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + , subq_11.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + , COUNT(DISTINCT subq_10.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_9.metric_time__day + , subq_9.metric_time__month + , subq_9.metric_time__year + , subq_9.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.ds_partitioned__day + , subq_8.ds_partitioned__week + , subq_8.ds_partitioned__month + , subq_8.ds_partitioned__quarter + , subq_8.ds_partitioned__year + , subq_8.ds_partitioned__extract_year + , subq_8.ds_partitioned__extract_quarter + , subq_8.ds_partitioned__extract_month + , subq_8.ds_partitioned__extract_day + , subq_8.ds_partitioned__extract_dow + , subq_8.ds_partitioned__extract_doy + , subq_8.paid_at__day + , subq_8.paid_at__week + , subq_8.paid_at__month + , subq_8.paid_at__quarter + , subq_8.paid_at__year + , subq_8.paid_at__extract_year + , subq_8.paid_at__extract_quarter + , subq_8.paid_at__extract_month + , subq_8.paid_at__extract_day + , subq_8.paid_at__extract_dow + , subq_8.paid_at__extract_doy + , subq_8.booking__ds__day + , subq_8.booking__ds__week + , subq_8.booking__ds__month + , subq_8.booking__ds__quarter + , subq_8.booking__ds__year + , subq_8.booking__ds__extract_year + , subq_8.booking__ds__extract_quarter + , subq_8.booking__ds__extract_month + , subq_8.booking__ds__extract_day + , subq_8.booking__ds__extract_dow + , subq_8.booking__ds__extract_doy + , subq_8.booking__ds_partitioned__day + , subq_8.booking__ds_partitioned__week + , subq_8.booking__ds_partitioned__month + , subq_8.booking__ds_partitioned__quarter + , subq_8.booking__ds_partitioned__year + , subq_8.booking__ds_partitioned__extract_year + , subq_8.booking__ds_partitioned__extract_quarter + , subq_8.booking__ds_partitioned__extract_month + , subq_8.booking__ds_partitioned__extract_day + , subq_8.booking__ds_partitioned__extract_dow + , subq_8.booking__ds_partitioned__extract_doy + , subq_8.booking__paid_at__day + , subq_8.booking__paid_at__week + , subq_8.booking__paid_at__month + , subq_8.booking__paid_at__quarter + , subq_8.booking__paid_at__year + , subq_8.booking__paid_at__extract_year + , subq_8.booking__paid_at__extract_quarter + , subq_8.booking__paid_at__extract_month + , subq_8.booking__paid_at__extract_day + , subq_8.booking__paid_at__extract_dow + , subq_8.booking__paid_at__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy + , subq_8.listing + , subq_8.guest + , subq_8.host + , subq_8.booking__listing + , subq_8.booking__guest + , subq_8.booking__host + , subq_8.is_instant + , subq_8.booking__is_instant + , subq_8.bookings + , subq_8.instant_bookings + , subq_8.booking_value + , subq_8.max_booking_value + , subq_8.min_booking_value + , subq_8.bookers + , subq_8.average_booking_value + , subq_8.referred_bookings + , subq_8.median_booking_value + , subq_8.booking_value_p99 + , subq_8.discrete_booking_value_p99 + , subq_8.approximate_continuous_booking_value_p99 + , subq_8.approximate_discrete_booking_value_p99 + 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_8 + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + ) subq_11 + ) subq_12 + ON + ( + subq_7.metric_time__day = subq_12.metric_time__day + ) AND ( + subq_7.metric_time__month = subq_12.metric_time__month + ) AND ( + subq_7.metric_time__year = subq_12.metric_time__year + ) + GROUP BY + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..d13f6c1eee --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,64 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) AS metric_time__day + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) AS metric_time__month + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) AS metric_time__year + , MAX(subq_21.booking_value) AS booking_value + , MAX(subq_26.bookers) AS bookers + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_17.ds AS metric_time__day + , DATE_TRUNC('month', subq_17.ds) AS metric_time__month + , DATE_TRUNC('year', subq_17.ds) AS metric_time__year + , SUM(bookings_source_src_28000.booking_value) AS booking_value + FROM ***************************.mf_time_spine subq_17 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + subq_17.ds - MAKE_INTERVAL(weeks => 1) = DATE_TRUNC('day', bookings_source_src_28000.ds) + GROUP BY + subq_17.ds + , DATE_TRUNC('month', subq_17.ds) + , DATE_TRUNC('year', subq_17.ds) + ) subq_21 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , DATE_TRUNC('year', ds) AS metric_time__year + , COUNT(DISTINCT guest_id) AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + , DATE_TRUNC('month', ds) + , DATE_TRUNC('year', ds) + ) subq_26 + ON + ( + subq_21.metric_time__day = subq_26.metric_time__day + ) AND ( + subq_21.metric_time__month = subq_26.metric_time__month + ) AND ( + subq_21.metric_time__year = subq_26.metric_time__year + ) + GROUP BY + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) +) subq_27 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql index 6119c32442..cb19216291 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(isodow FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql index 5de6ed2213..3444c0bc35 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 9253341492..dd82b1c685 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -26,6 +26,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , CASE WHEN EXTRACT(dow FROM subq_5.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_5.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_5.metric_time__day) END AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 72735021e2..2b3e35d6a0 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -21,6 +21,11 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__month AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month , subq_1.monthly_ds__quarter AS monthly_ds__quarter , subq_1.monthly_ds__year AS monthly_ds__year diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql index a333cc466e..4b4b364667 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , CASE WHEN EXTRACT(dow FROM subq_7.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_7.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_7.metric_time__day) END AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 2854b80a91..7cb1f9cebc 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , CASE WHEN EXTRACT(dow FROM subq_7.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_7.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_7.metric_time__day) END AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql index 295528dc7d..499afa7d23 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , CASE WHEN EXTRACT(dow FROM subq_7.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_7.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_7.metric_time__day) END AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql index a16cfaacee..9536a26c3a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , CASE WHEN EXTRACT(dow FROM subq_7.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_7.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_7.metric_time__day) END AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 66be39403c..f1bb8e7757 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -27,6 +27,16 @@ 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 @@ -342,6 +352,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , CASE WHEN EXTRACT(dow FROM subq_10.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_10.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_10.metric_time__day) END AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 59f2c6a72e..733b6ea4ff 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -26,7 +26,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 @@ -342,7 +352,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , CASE WHEN EXTRACT(dow FROM subq_10.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_10.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_10.metric_time__day) END AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 9094d823b4..bf8bf141c3 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -254,6 +254,16 @@ FROM ( -- Join to Time Spine Dataset 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_8.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_8.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_8.metric_time__day) END 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql index 7e26afdb2d..29881a2a31 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , CASE WHEN EXTRACT(dow FROM subq_5.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_5.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_5.metric_time__day) END AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 8ab2981ff7..8cd0c3811d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -27,6 +27,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_2.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM subq_2.booking__ds__day) = 0 THEN EXTRACT(dow FROM subq_2.booking__ds__day) + 7 ELSE EXTRACT(dow FROM subq_2.booking__ds__day) END AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_2.booking__ds__day) AS booking__ds__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql index 21bca78b46..ccd62b038a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 6766f95854..f8cf399747 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -53,6 +53,16 @@ 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql index 7cae1db2ae..eb43b032d0 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql @@ -37,6 +37,16 @@ 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql index 3357ad2ae4..62277068b6 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql @@ -38,6 +38,16 @@ 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql index 9f4c34396d..b804aa0a07 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql @@ -42,6 +42,16 @@ 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..d92d99a040 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,345 @@ +-- Compute Metrics via Expressions +SELECT + subq_9.metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.bookings + 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + 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 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 +) subq_9 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..bfd3b8fbce --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,36 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(bookings) AS bookings_start_of_month + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_13.ds AS metric_time__day + , DATE_TRUNC('month', subq_13.ds) AS metric_time__month + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine subq_13 + 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_11 + ON + DATE_TRUNC('month', subq_13.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', subq_13.ds) = subq_13.ds + ) subq_15 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month +) subq_19 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..7dc8ce399a --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -0,0 +1,339 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.bookings + 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 +) subq_7 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..76767e46c6 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,32 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_11.ds AS metric_time__day + , DATE_TRUNC('month', subq_11.ds) AS metric_time__month + , DATE_TRUNC('year', subq_11.ds) AS metric_time__year + , SUM(subq_9.bookings) AS bookings_start_of_month + FROM ***************************.mf_time_spine subq_11 + 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_9 + ON + DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + GROUP BY + subq_11.ds + , DATE_TRUNC('month', subq_11.ds) + , DATE_TRUNC('year', subq_11.ds) +) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql index 5576dc36ba..3f9c5238ed 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM subq_7.booking__ds__day) = 0 THEN EXTRACT(dow FROM subq_7.booking__ds__day) + 7 ELSE EXTRACT(dow FROM subq_7.booking__ds__day) END AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..6df1021844 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) AS metric_time__month + , MAX(subq_9.booking_value) AS booking_value + , MAX(subq_16.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.booking_value + 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_15.metric_time__month + , subq_15.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_14.metric_time__month + , COUNT(DISTINCT subq_14.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month'] + SELECT + subq_13.metric_time__month + , subq_13.bookers + FROM ( + -- Constrain Output with WHERE + SELECT + subq_12.metric_time__day + , subq_12.metric_time__month + , subq_12.bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + WHERE metric_time__day = '2020-01-01' + ) subq_13 + ) subq_14 + GROUP BY + subq_14.metric_time__month + ) subq_15 + ) subq_16 + ON + subq_9.metric_time__month = subq_16.metric_time__month + GROUP BY + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) +) subq_17 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..da44e813f4 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,62 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) AS metric_time__month + , MAX(subq_27.booking_value) AS booking_value + , MAX(subq_34.bookers) AS bookers + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(booking_value) AS booking_value + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_21.ds AS metric_time__day + , DATE_TRUNC('month', subq_21.ds) AS metric_time__month + , bookings_source_src_28000.booking_value AS booking_value + FROM ***************************.mf_time_spine subq_21 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + DATEADD(week, -1, subq_21.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + ) subq_23 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_27 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookers', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , COUNT(DISTINCT bookers) AS bookers + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , guest_id AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_30 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_34 + ON + subq_27.metric_time__month = subq_34.metric_time__month + GROUP BY + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) +) subq_35 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..0559050090 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql @@ -0,0 +1,583 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , subq_13.metric_time__month + , subq_13.metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) AS metric_time__month + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) AS metric_time__year + , MAX(subq_7.booking_value) AS booking_value + , MAX(subq_12.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.booking_value + 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 + ) subq_7 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + , subq_11.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + , COUNT(DISTINCT subq_10.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_9.metric_time__day + , subq_9.metric_time__month + , subq_9.metric_time__year + , subq_9.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.ds_partitioned__day + , subq_8.ds_partitioned__week + , subq_8.ds_partitioned__month + , subq_8.ds_partitioned__quarter + , subq_8.ds_partitioned__year + , subq_8.ds_partitioned__extract_year + , subq_8.ds_partitioned__extract_quarter + , subq_8.ds_partitioned__extract_month + , subq_8.ds_partitioned__extract_day + , subq_8.ds_partitioned__extract_dow + , subq_8.ds_partitioned__extract_doy + , subq_8.paid_at__day + , subq_8.paid_at__week + , subq_8.paid_at__month + , subq_8.paid_at__quarter + , subq_8.paid_at__year + , subq_8.paid_at__extract_year + , subq_8.paid_at__extract_quarter + , subq_8.paid_at__extract_month + , subq_8.paid_at__extract_day + , subq_8.paid_at__extract_dow + , subq_8.paid_at__extract_doy + , subq_8.booking__ds__day + , subq_8.booking__ds__week + , subq_8.booking__ds__month + , subq_8.booking__ds__quarter + , subq_8.booking__ds__year + , subq_8.booking__ds__extract_year + , subq_8.booking__ds__extract_quarter + , subq_8.booking__ds__extract_month + , subq_8.booking__ds__extract_day + , subq_8.booking__ds__extract_dow + , subq_8.booking__ds__extract_doy + , subq_8.booking__ds_partitioned__day + , subq_8.booking__ds_partitioned__week + , subq_8.booking__ds_partitioned__month + , subq_8.booking__ds_partitioned__quarter + , subq_8.booking__ds_partitioned__year + , subq_8.booking__ds_partitioned__extract_year + , subq_8.booking__ds_partitioned__extract_quarter + , subq_8.booking__ds_partitioned__extract_month + , subq_8.booking__ds_partitioned__extract_day + , subq_8.booking__ds_partitioned__extract_dow + , subq_8.booking__ds_partitioned__extract_doy + , subq_8.booking__paid_at__day + , subq_8.booking__paid_at__week + , subq_8.booking__paid_at__month + , subq_8.booking__paid_at__quarter + , subq_8.booking__paid_at__year + , subq_8.booking__paid_at__extract_year + , subq_8.booking__paid_at__extract_quarter + , subq_8.booking__paid_at__extract_month + , subq_8.booking__paid_at__extract_day + , subq_8.booking__paid_at__extract_dow + , subq_8.booking__paid_at__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy + , subq_8.listing + , subq_8.guest + , subq_8.host + , subq_8.booking__listing + , subq_8.booking__guest + , subq_8.booking__host + , subq_8.is_instant + , subq_8.booking__is_instant + , subq_8.bookings + , subq_8.instant_bookings + , subq_8.booking_value + , subq_8.max_booking_value + , subq_8.min_booking_value + , subq_8.bookers + , subq_8.average_booking_value + , subq_8.referred_bookings + , subq_8.median_booking_value + , subq_8.booking_value_p99 + , subq_8.discrete_booking_value_p99 + , subq_8.approximate_continuous_booking_value_p99 + , subq_8.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds) END AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.ds_partitioned) END AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , CASE WHEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) = 0 THEN EXTRACT(dow FROM bookings_source_src_28000.paid_at) + 7 ELSE EXTRACT(dow FROM bookings_source_src_28000.paid_at) END AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_8 + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + ) subq_11 + ) subq_12 + ON + ( + subq_7.metric_time__day = subq_12.metric_time__day + ) AND ( + subq_7.metric_time__month = subq_12.metric_time__month + ) AND ( + subq_7.metric_time__year = subq_12.metric_time__year + ) + GROUP BY + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..58b1be36eb --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,64 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) AS metric_time__day + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) AS metric_time__month + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) AS metric_time__year + , MAX(subq_21.booking_value) AS booking_value + , MAX(subq_26.bookers) AS bookers + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_17.ds AS metric_time__day + , DATE_TRUNC('month', subq_17.ds) AS metric_time__month + , DATE_TRUNC('year', subq_17.ds) AS metric_time__year + , SUM(bookings_source_src_28000.booking_value) AS booking_value + FROM ***************************.mf_time_spine subq_17 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + GROUP BY + subq_17.ds + , DATE_TRUNC('month', subq_17.ds) + , DATE_TRUNC('year', subq_17.ds) + ) subq_21 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , DATE_TRUNC('year', ds) AS metric_time__year + , COUNT(DISTINCT guest_id) AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + , DATE_TRUNC('month', ds) + , DATE_TRUNC('year', ds) + ) subq_26 + ON + ( + subq_21.metric_time__day = subq_26.metric_time__day + ) AND ( + subq_21.metric_time__month = subq_26.metric_time__month + ) AND ( + subq_21.metric_time__year = subq_26.metric_time__year + ) + GROUP BY + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) +) subq_27 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql index 89611c0021..d00776cddd 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , CASE WHEN EXTRACT(dow FROM subq_7.booking__ds__day) = 0 THEN EXTRACT(dow FROM subq_7.booking__ds__day) + 7 ELSE EXTRACT(dow FROM subq_7.booking__ds__day) END AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql index 168532395f..898f838fe5 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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 + , CASE WHEN EXTRACT(dow FROM subq_2.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_2.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_2.metric_time__day) END 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index da5cc04173..3312de2574 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -26,6 +26,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(dayofweekiso FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 72735021e2..2b3e35d6a0 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -21,6 +21,11 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__month AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month , subq_1.monthly_ds__quarter AS monthly_ds__quarter , subq_1.monthly_ds__year AS monthly_ds__year diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql index f808031fe8..e66b477c12 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(dayofweekiso FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 286af4ea9e..b264cf74f6 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(dayofweekiso FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql index ad845f2bdb..203ba0d691 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(dayofweekiso FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 9fde039432..a72e8fe18b 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(dayofweekiso FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index d87c40b6ae..d49e78644e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -27,6 +27,16 @@ 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 DATE_TRUNC('day', 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(dayofweekiso 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 @@ -342,6 +352,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(dayofweekiso FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 0306d01097..9f73dd700c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -26,7 +26,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + 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 DATE_TRUNC('day', 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(dayofweekiso 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 @@ -342,7 +352,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(dayofweekiso FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 40f681f572..071ed2411f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -254,6 +254,16 @@ FROM ( -- Join to Time Spine Dataset 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 DATE_TRUNC('day', 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(dayofweekiso 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql index 4e7572903b..912e9e864e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(dayofweekiso FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql index bc91fc52da..4dade49a7c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -27,6 +27,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_2.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM subq_2.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_2.booking__ds__day) AS booking__ds__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql index 20692b64b0..969bf5c74c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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(dayofweekiso 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index a6dfeab8d9..fffb4a75b8 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -53,6 +53,16 @@ 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 DATE_TRUNC('day', 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(dayofweekiso 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql index d1fe107e61..4eedab48bd 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql @@ -37,6 +37,16 @@ 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 DATE_TRUNC('day', 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(dayofweekiso 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql index c9a7077f9a..ebb1e61bbd 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql @@ -38,6 +38,16 @@ 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 DATE_TRUNC('day', 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(dayofweekiso 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql index 1930a413d0..605ce6c166 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql @@ -42,6 +42,16 @@ 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 DATE_TRUNC('day', 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(dayofweekiso 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..b2ad329128 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,345 @@ +-- Compute Metrics via Expressions +SELECT + subq_9.metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.bookings + 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 DATE_TRUNC('day', 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(dayofweekiso 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + 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 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 +) subq_9 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..bfd3b8fbce --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,36 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(bookings) AS bookings_start_of_month + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_13.ds AS metric_time__day + , DATE_TRUNC('month', subq_13.ds) AS metric_time__month + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine subq_13 + 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_11 + ON + DATE_TRUNC('month', subq_13.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', subq_13.ds) = subq_13.ds + ) subq_15 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month +) subq_19 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..6928c03ba1 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -0,0 +1,339 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.bookings + 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 DATE_TRUNC('day', 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(dayofweekiso 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 +) subq_7 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..76767e46c6 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,32 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_11.ds AS metric_time__day + , DATE_TRUNC('month', subq_11.ds) AS metric_time__month + , DATE_TRUNC('year', subq_11.ds) AS metric_time__year + , SUM(subq_9.bookings) AS bookings_start_of_month + FROM ***************************.mf_time_spine subq_11 + 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_9 + ON + DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + GROUP BY + subq_11.ds + , DATE_TRUNC('month', subq_11.ds) + , DATE_TRUNC('year', subq_11.ds) +) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql index 5a3bda419b..8a86991b51 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..17b50cf308 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) AS metric_time__month + , MAX(subq_9.booking_value) AS booking_value + , MAX(subq_16.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.booking_value + 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 DATE_TRUNC('day', 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(dayofweekiso 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_15.metric_time__month + , subq_15.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_14.metric_time__month + , COUNT(DISTINCT subq_14.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month'] + SELECT + subq_13.metric_time__month + , subq_13.bookers + FROM ( + -- Constrain Output with WHERE + SELECT + subq_12.metric_time__day + , subq_12.metric_time__month + , subq_12.bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + WHERE metric_time__day = '2020-01-01' + ) subq_13 + ) subq_14 + GROUP BY + subq_14.metric_time__month + ) subq_15 + ) subq_16 + ON + subq_9.metric_time__month = subq_16.metric_time__month + GROUP BY + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) +) subq_17 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..da44e813f4 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,62 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) AS metric_time__month + , MAX(subq_27.booking_value) AS booking_value + , MAX(subq_34.bookers) AS bookers + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(booking_value) AS booking_value + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_21.ds AS metric_time__day + , DATE_TRUNC('month', subq_21.ds) AS metric_time__month + , bookings_source_src_28000.booking_value AS booking_value + FROM ***************************.mf_time_spine subq_21 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + DATEADD(week, -1, subq_21.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + ) subq_23 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_27 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookers', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , COUNT(DISTINCT bookers) AS bookers + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , guest_id AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_30 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_34 + ON + subq_27.metric_time__month = subq_34.metric_time__month + GROUP BY + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) +) subq_35 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..0f47dd4f42 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql @@ -0,0 +1,583 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , subq_13.metric_time__month + , subq_13.metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) AS metric_time__month + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) AS metric_time__year + , MAX(subq_7.booking_value) AS booking_value + , MAX(subq_12.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.booking_value + 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 DATE_TRUNC('day', 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(dayofweekiso 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATEADD(week, -1, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 + ) subq_7 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + , subq_11.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + , COUNT(DISTINCT subq_10.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_9.metric_time__day + , subq_9.metric_time__month + , subq_9.metric_time__year + , subq_9.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.ds_partitioned__day + , subq_8.ds_partitioned__week + , subq_8.ds_partitioned__month + , subq_8.ds_partitioned__quarter + , subq_8.ds_partitioned__year + , subq_8.ds_partitioned__extract_year + , subq_8.ds_partitioned__extract_quarter + , subq_8.ds_partitioned__extract_month + , subq_8.ds_partitioned__extract_day + , subq_8.ds_partitioned__extract_dow + , subq_8.ds_partitioned__extract_doy + , subq_8.paid_at__day + , subq_8.paid_at__week + , subq_8.paid_at__month + , subq_8.paid_at__quarter + , subq_8.paid_at__year + , subq_8.paid_at__extract_year + , subq_8.paid_at__extract_quarter + , subq_8.paid_at__extract_month + , subq_8.paid_at__extract_day + , subq_8.paid_at__extract_dow + , subq_8.paid_at__extract_doy + , subq_8.booking__ds__day + , subq_8.booking__ds__week + , subq_8.booking__ds__month + , subq_8.booking__ds__quarter + , subq_8.booking__ds__year + , subq_8.booking__ds__extract_year + , subq_8.booking__ds__extract_quarter + , subq_8.booking__ds__extract_month + , subq_8.booking__ds__extract_day + , subq_8.booking__ds__extract_dow + , subq_8.booking__ds__extract_doy + , subq_8.booking__ds_partitioned__day + , subq_8.booking__ds_partitioned__week + , subq_8.booking__ds_partitioned__month + , subq_8.booking__ds_partitioned__quarter + , subq_8.booking__ds_partitioned__year + , subq_8.booking__ds_partitioned__extract_year + , subq_8.booking__ds_partitioned__extract_quarter + , subq_8.booking__ds_partitioned__extract_month + , subq_8.booking__ds_partitioned__extract_day + , subq_8.booking__ds_partitioned__extract_dow + , subq_8.booking__ds_partitioned__extract_doy + , subq_8.booking__paid_at__day + , subq_8.booking__paid_at__week + , subq_8.booking__paid_at__month + , subq_8.booking__paid_at__quarter + , subq_8.booking__paid_at__year + , subq_8.booking__paid_at__extract_year + , subq_8.booking__paid_at__extract_quarter + , subq_8.booking__paid_at__extract_month + , subq_8.booking__paid_at__extract_day + , subq_8.booking__paid_at__extract_dow + , subq_8.booking__paid_at__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy + , subq_8.listing + , subq_8.guest + , subq_8.host + , subq_8.booking__listing + , subq_8.booking__guest + , subq_8.booking__host + , subq_8.is_instant + , subq_8.booking__is_instant + , subq_8.bookings + , subq_8.instant_bookings + , subq_8.booking_value + , subq_8.max_booking_value + , subq_8.min_booking_value + , subq_8.bookers + , subq_8.average_booking_value + , subq_8.referred_bookings + , subq_8.median_booking_value + , subq_8.booking_value_p99 + , subq_8.discrete_booking_value_p99 + , subq_8.approximate_continuous_booking_value_p99 + , subq_8.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(dayofweekiso FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_8 + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + ) subq_11 + ) subq_12 + ON + ( + subq_7.metric_time__day = subq_12.metric_time__day + ) AND ( + subq_7.metric_time__month = subq_12.metric_time__month + ) AND ( + subq_7.metric_time__year = subq_12.metric_time__year + ) + GROUP BY + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..58b1be36eb --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,64 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) AS metric_time__day + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) AS metric_time__month + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) AS metric_time__year + , MAX(subq_21.booking_value) AS booking_value + , MAX(subq_26.bookers) AS bookers + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_17.ds AS metric_time__day + , DATE_TRUNC('month', subq_17.ds) AS metric_time__month + , DATE_TRUNC('year', subq_17.ds) AS metric_time__year + , SUM(bookings_source_src_28000.booking_value) AS booking_value + FROM ***************************.mf_time_spine subq_17 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + DATEADD(week, -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + GROUP BY + subq_17.ds + , DATE_TRUNC('month', subq_17.ds) + , DATE_TRUNC('year', subq_17.ds) + ) subq_21 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , DATE_TRUNC('year', ds) AS metric_time__year + , COUNT(DISTINCT guest_id) AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + , DATE_TRUNC('month', ds) + , DATE_TRUNC('year', ds) + ) subq_26 + ON + ( + subq_21.metric_time__day = subq_26.metric_time__day + ) AND ( + subq_21.metric_time__month = subq_26.metric_time__month + ) AND ( + subq_21.metric_time__year = subq_26.metric_time__year + ) + GROUP BY + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) +) subq_27 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql index 0d6d8ebe5b..ee5e543017 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(dayofweekiso FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql index e54aba202e..2002794d0a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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(dayofweekiso 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 87af1e5e68..eb0a49b46d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -26,6 +26,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 882a8d8d02..3f17f3a766 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -21,6 +21,11 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.metric_time__month AS metric_time__month + , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter + , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month , subq_1.monthly_ds__quarter AS monthly_ds__quarter , subq_1.monthly_ds__year AS monthly_ds__year diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql index 29678f18b8..3e6dc1b7db 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index d0e67ac561..966d7ff296 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql index e19cad2a47..d43892ad7f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 0550ff5929..d2e0aedb53 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 2a1a1b759c..15f6e068b1 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -27,6 +27,16 @@ 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 @@ -342,6 +352,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 3f2c2d6ce9..7933040c75 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -26,7 +26,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 @@ -342,7 +352,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 2f49b10812..f016a9b7db 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -254,6 +254,16 @@ FROM ( -- Join to Time Spine Dataset 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql index f8accaaf66..7b87d6d566 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql @@ -21,6 +21,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_5.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_5.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy , subq_4.ds__day AS ds__day , subq_4.ds__week AS ds__week , subq_4.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 621e2e9fab..9f2cdb9266 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -27,6 +27,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_2.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_2.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_2.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_2.booking__ds__day) AS booking__ds__extract_doy , subq_1.ds__day AS ds__day , subq_1.ds__week AS ds__week , subq_1.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql index bef366d149..c54fdc5fdc 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 2f05f950c6..12d140dba7 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -53,6 +53,16 @@ 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql index a51da3cdb3..fa7a593c6d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql @@ -37,6 +37,16 @@ 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql index 71a9ec40bd..ab68677f9c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql @@ -38,6 +38,16 @@ 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql index b579d46c04..ae0aa7c66d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql @@ -42,6 +42,16 @@ 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..16bd80f75b --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,345 @@ +-- Compute Metrics via Expressions +SELECT + subq_9.metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.bookings + 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + 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 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 +) subq_9 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..bfd3b8fbce --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,36 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookings', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(bookings) AS bookings_start_of_month + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + SELECT + subq_13.ds AS metric_time__day + , DATE_TRUNC('month', subq_13.ds) AS metric_time__month + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine subq_13 + 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_11 + ON + DATE_TRUNC('month', subq_13.ds) = subq_11.metric_time__day + WHERE DATE_TRUNC('month', subq_13.ds) = subq_13.ds + ) subq_15 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month +) subq_19 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..811e12ab3e --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -0,0 +1,339 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.metric_time__day + , subq_7.metric_time__month + , subq_7.metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.bookings AS bookings_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.bookings) AS bookings + FROM ( + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.bookings + 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 +) subq_7 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..76767e46c6 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,32 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , bookings_start_of_month AS bookings_at_start_of_month +FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_11.ds AS metric_time__day + , DATE_TRUNC('month', subq_11.ds) AS metric_time__month + , DATE_TRUNC('year', subq_11.ds) AS metric_time__year + , SUM(subq_9.bookings) AS bookings_start_of_month + FROM ***************************.mf_time_spine subq_11 + 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_9 + ON + DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + GROUP BY + subq_11.ds + , DATE_TRUNC('month', subq_11.ds) + , DATE_TRUNC('year', subq_11.ds) +) subq_15 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql index c8feb12b1a..df25d92345 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql new file mode 100644 index 0000000000..6fdfb94137 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -0,0 +1,585 @@ +-- Compute Metrics via Expressions +SELECT + subq_17.metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) AS metric_time__month + , MAX(subq_9.booking_value) AS booking_value + , MAX(subq_16.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_8.metric_time__month + , subq_8.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_7.metric_time__month + , SUM(subq_7.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + SELECT + subq_6.metric_time__month + , subq_6.booking_value + FROM ( + -- Constrain Output with WHERE + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.booking_value + 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATE_ADD('week', -1, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + WHERE metric_time__day = '2020-01-01' + ) subq_6 + ) subq_7 + GROUP BY + subq_7.metric_time__month + ) subq_8 + ) subq_9 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_15.metric_time__month + , subq_15.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_14.metric_time__month + , COUNT(DISTINCT subq_14.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month'] + SELECT + subq_13.metric_time__month + , subq_13.bookers + FROM ( + -- Constrain Output with WHERE + SELECT + subq_12.metric_time__day + , subq_12.metric_time__month + , subq_12.bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.ds_partitioned__day + , subq_10.ds_partitioned__week + , subq_10.ds_partitioned__month + , subq_10.ds_partitioned__quarter + , subq_10.ds_partitioned__year + , subq_10.ds_partitioned__extract_year + , subq_10.ds_partitioned__extract_quarter + , subq_10.ds_partitioned__extract_month + , subq_10.ds_partitioned__extract_day + , subq_10.ds_partitioned__extract_dow + , subq_10.ds_partitioned__extract_doy + , subq_10.paid_at__day + , subq_10.paid_at__week + , subq_10.paid_at__month + , subq_10.paid_at__quarter + , subq_10.paid_at__year + , subq_10.paid_at__extract_year + , subq_10.paid_at__extract_quarter + , subq_10.paid_at__extract_month + , subq_10.paid_at__extract_day + , subq_10.paid_at__extract_dow + , subq_10.paid_at__extract_doy + , subq_10.booking__ds__day + , subq_10.booking__ds__week + , subq_10.booking__ds__month + , subq_10.booking__ds__quarter + , subq_10.booking__ds__year + , subq_10.booking__ds__extract_year + , subq_10.booking__ds__extract_quarter + , subq_10.booking__ds__extract_month + , subq_10.booking__ds__extract_day + , subq_10.booking__ds__extract_dow + , subq_10.booking__ds__extract_doy + , subq_10.booking__ds_partitioned__day + , subq_10.booking__ds_partitioned__week + , subq_10.booking__ds_partitioned__month + , subq_10.booking__ds_partitioned__quarter + , subq_10.booking__ds_partitioned__year + , subq_10.booking__ds_partitioned__extract_year + , subq_10.booking__ds_partitioned__extract_quarter + , subq_10.booking__ds_partitioned__extract_month + , subq_10.booking__ds_partitioned__extract_day + , subq_10.booking__ds_partitioned__extract_dow + , subq_10.booking__ds_partitioned__extract_doy + , subq_10.booking__paid_at__day + , subq_10.booking__paid_at__week + , subq_10.booking__paid_at__month + , subq_10.booking__paid_at__quarter + , subq_10.booking__paid_at__year + , subq_10.booking__paid_at__extract_year + , subq_10.booking__paid_at__extract_quarter + , subq_10.booking__paid_at__extract_month + , subq_10.booking__paid_at__extract_day + , subq_10.booking__paid_at__extract_dow + , subq_10.booking__paid_at__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.listing + , subq_10.guest + , subq_10.host + , subq_10.booking__listing + , subq_10.booking__guest + , subq_10.booking__host + , subq_10.is_instant + , subq_10.booking__is_instant + , subq_10.bookings + , subq_10.instant_bookings + , subq_10.booking_value + , subq_10.max_booking_value + , subq_10.min_booking_value + , subq_10.bookers + , subq_10.average_booking_value + , subq_10.referred_bookings + , subq_10.median_booking_value + , subq_10.booking_value_p99 + , subq_10.discrete_booking_value_p99 + , subq_10.approximate_continuous_booking_value_p99 + , subq_10.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + WHERE metric_time__day = '2020-01-01' + ) subq_13 + ) subq_14 + GROUP BY + subq_14.metric_time__month + ) subq_15 + ) subq_16 + ON + subq_9.metric_time__month = subq_16.metric_time__month + GROUP BY + COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) +) subq_17 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..5b548d42a9 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0_optimized.sql @@ -0,0 +1,62 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__month + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) AS metric_time__month + , MAX(subq_27.booking_value) AS booking_value + , MAX(subq_34.bookers) AS bookers + FROM ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['booking_value', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , SUM(booking_value) AS booking_value + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + SELECT + subq_21.ds AS metric_time__day + , DATE_TRUNC('month', subq_21.ds) AS metric_time__month + , bookings_source_src_28000.booking_value AS booking_value + FROM ***************************.mf_time_spine subq_21 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + DATE_ADD('week', -1, subq_21.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + ) subq_23 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_27 + FULL OUTER JOIN ( + -- Constrain Output with WHERE + -- Pass Only Elements: ['bookers', 'metric_time__month'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__month + , COUNT(DISTINCT bookers) AS bookers + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , guest_id AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_30 + WHERE metric_time__day = '2020-01-01' + GROUP BY + metric_time__month + ) subq_34 + ON + subq_27.metric_time__month = subq_34.metric_time__month + GROUP BY + COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) +) subq_35 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql new file mode 100644 index 0000000000..3fd4cf1276 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql @@ -0,0 +1,583 @@ +-- Compute Metrics via Expressions +SELECT + subq_13.metric_time__day + , subq_13.metric_time__month + , subq_13.metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) AS metric_time__month + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) AS metric_time__year + , MAX(subq_7.booking_value) AS booking_value + , MAX(subq_12.bookers) AS bookers + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.metric_time__year + , subq_6.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , SUM(subq_5.booking_value) AS booking_value + FROM ( + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , subq_4.booking_value + 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 ( + -- Time Spine + SELECT + 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 ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATE_ADD('week', -1, subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 + ) subq_5 + GROUP BY + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + ) subq_6 + ) subq_7 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.metric_time__year + , subq_11.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + , COUNT(DISTINCT subq_10.bookers) AS bookers + FROM ( + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_9.metric_time__day + , subq_9.metric_time__month + , subq_9.metric_time__year + , subq_9.bookers + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.ds_partitioned__day + , subq_8.ds_partitioned__week + , subq_8.ds_partitioned__month + , subq_8.ds_partitioned__quarter + , subq_8.ds_partitioned__year + , subq_8.ds_partitioned__extract_year + , subq_8.ds_partitioned__extract_quarter + , subq_8.ds_partitioned__extract_month + , subq_8.ds_partitioned__extract_day + , subq_8.ds_partitioned__extract_dow + , subq_8.ds_partitioned__extract_doy + , subq_8.paid_at__day + , subq_8.paid_at__week + , subq_8.paid_at__month + , subq_8.paid_at__quarter + , subq_8.paid_at__year + , subq_8.paid_at__extract_year + , subq_8.paid_at__extract_quarter + , subq_8.paid_at__extract_month + , subq_8.paid_at__extract_day + , subq_8.paid_at__extract_dow + , subq_8.paid_at__extract_doy + , subq_8.booking__ds__day + , subq_8.booking__ds__week + , subq_8.booking__ds__month + , subq_8.booking__ds__quarter + , subq_8.booking__ds__year + , subq_8.booking__ds__extract_year + , subq_8.booking__ds__extract_quarter + , subq_8.booking__ds__extract_month + , subq_8.booking__ds__extract_day + , subq_8.booking__ds__extract_dow + , subq_8.booking__ds__extract_doy + , subq_8.booking__ds_partitioned__day + , subq_8.booking__ds_partitioned__week + , subq_8.booking__ds_partitioned__month + , subq_8.booking__ds_partitioned__quarter + , subq_8.booking__ds_partitioned__year + , subq_8.booking__ds_partitioned__extract_year + , subq_8.booking__ds_partitioned__extract_quarter + , subq_8.booking__ds_partitioned__extract_month + , subq_8.booking__ds_partitioned__extract_day + , subq_8.booking__ds_partitioned__extract_dow + , subq_8.booking__ds_partitioned__extract_doy + , subq_8.booking__paid_at__day + , subq_8.booking__paid_at__week + , subq_8.booking__paid_at__month + , subq_8.booking__paid_at__quarter + , subq_8.booking__paid_at__year + , subq_8.booking__paid_at__extract_year + , subq_8.booking__paid_at__extract_quarter + , subq_8.booking__paid_at__extract_month + , subq_8.booking__paid_at__extract_day + , subq_8.booking__paid_at__extract_dow + , subq_8.booking__paid_at__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy + , subq_8.listing + , subq_8.guest + , subq_8.host + , subq_8.booking__listing + , subq_8.booking__guest + , subq_8.booking__host + , subq_8.is_instant + , subq_8.booking__is_instant + , subq_8.bookings + , subq_8.instant_bookings + , subq_8.booking_value + , subq_8.max_booking_value + , subq_8.min_booking_value + , subq_8.bookers + , subq_8.average_booking_value + , subq_8.referred_bookings + , subq_8.median_booking_value + , subq_8.booking_value_p99 + , subq_8.discrete_booking_value_p99 + , subq_8.approximate_continuous_booking_value_p99 + , subq_8.approximate_discrete_booking_value_p99 + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + SELECT + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.booking_value + , bookings_source_src_28000.booking_value AS max_booking_value + , bookings_source_src_28000.booking_value AS min_booking_value + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + , bookings_source_src_28000.booking_value AS booking_payments + , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings + , bookings_source_src_28000.booking_value AS median_booking_value + , bookings_source_src_28000.booking_value AS booking_value_p99 + , bookings_source_src_28000.booking_value AS discrete_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_continuous_booking_value_p99 + , bookings_source_src_28000.booking_value AS approximate_discrete_booking_value_p99 + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS paid_at__extract_doy + , bookings_source_src_28000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_28000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_28000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_28000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_28000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_28000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_28000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_28000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_28000.listing_id AS listing + , bookings_source_src_28000.guest_id AS guest + , bookings_source_src_28000.host_id AS host + , bookings_source_src_28000.listing_id AS booking__listing + , bookings_source_src_28000.guest_id AS booking__guest + , bookings_source_src_28000.host_id AS booking__host + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_8 + ) subq_9 + ) subq_10 + GROUP BY + subq_10.metric_time__day + , subq_10.metric_time__month + , subq_10.metric_time__year + ) subq_11 + ) subq_12 + ON + ( + subq_7.metric_time__day = subq_12.metric_time__day + ) AND ( + subq_7.metric_time__month = subq_12.metric_time__month + ) AND ( + subq_7.metric_time__year = subq_12.metric_time__year + ) + GROUP BY + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) + , COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) + , COALESCE(subq_7.metric_time__year, subq_12.metric_time__year) +) subq_13 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0_optimized.sql new file mode 100644 index 0000000000..183eb8a765 --- /dev/null +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0_optimized.sql @@ -0,0 +1,64 @@ +-- Compute Metrics via Expressions +SELECT + metric_time__day + , metric_time__month + , metric_time__year + , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week +FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) AS metric_time__day + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) AS metric_time__month + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) AS metric_time__year + , MAX(subq_21.booking_value) AS booking_value + , MAX(subq_26.bookers) AS bookers + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + subq_17.ds AS metric_time__day + , DATE_TRUNC('month', subq_17.ds) AS metric_time__month + , DATE_TRUNC('year', subq_17.ds) AS metric_time__year + , SUM(bookings_source_src_28000.booking_value) AS booking_value + FROM ***************************.mf_time_spine subq_17 + INNER JOIN + ***************************.fct_bookings bookings_source_src_28000 + ON + DATE_ADD('week', -1, subq_17.ds) = DATE_TRUNC('day', bookings_source_src_28000.ds) + GROUP BY + subq_17.ds + , DATE_TRUNC('month', subq_17.ds) + , DATE_TRUNC('year', subq_17.ds) + ) subq_21 + FULL OUTER JOIN ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , DATE_TRUNC('month', ds) AS metric_time__month + , DATE_TRUNC('year', ds) AS metric_time__year + , COUNT(DISTINCT guest_id) AS bookers + FROM ***************************.fct_bookings bookings_source_src_28000 + GROUP BY + DATE_TRUNC('day', ds) + , DATE_TRUNC('month', ds) + , DATE_TRUNC('year', ds) + ) subq_26 + ON + ( + subq_21.metric_time__day = subq_26.metric_time__day + ) AND ( + subq_21.metric_time__month = subq_26.metric_time__month + ) AND ( + subq_21.metric_time__year = subq_26.metric_time__year + ) + GROUP BY + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) + , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) + , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) +) subq_27 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql index dc3bb6ba00..9e3c1baff4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql @@ -242,6 +242,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_7.booking__ds__day AS booking__ds__day + , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week + , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month + , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter + , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter + , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month + , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_7.booking__ds__day) AS booking__ds__extract_dow + , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql index 4c5c9f530d..18b04ecaf4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql @@ -21,6 +21,16 @@ 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 DATE_TRUNC('day', 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(DAY_OF_WEEK 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 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql index babc30dd11..902a797b7d 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -256,6 +256,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_10.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_10.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_10.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_10.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_10.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , IF(EXTRACT(dayofweek FROM subq_10.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_10.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 742c2e1f84..5ee0f4feb8 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -256,6 +256,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 7036ffbc8e..1f0c027154 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -256,6 +256,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 994dbd8b88..cb63347d0c 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -256,6 +256,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , CASE WHEN EXTRACT(dow FROM subq_10.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_10.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_10.metric_time__day) END AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 0399df1d6d..1c065b2f6c 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -256,6 +256,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(dayofweekiso FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql index caed9934dc..25062782ab 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -256,6 +256,16 @@ FROM ( -- Join to Time Spine Dataset SELECT subq_10.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_10.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy , subq_9.ds__day AS ds__day , subq_9.ds__week AS ds__week , subq_9.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql index e8bc68a8d4..6b4b711158 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - IF(EXTRACT(dayofweek FROM subq_7.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_7.metric_time__day) - 1) AS metric_time__extract_dow + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC(subq_7.metric_time__day, isoweek) AS metric_time__week + , DATE_TRUNC(subq_7.metric_time__day, month) AS metric_time__month + , DATE_TRUNC(subq_7.metric_time__day, quarter) AS metric_time__quarter + , DATE_TRUNC(subq_7.metric_time__day, year) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC(subq_7.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , IF(EXTRACT(dayofweek FROM subq_7.metric_time__day) = 1, 7, EXTRACT(dayofweek FROM subq_7.metric_time__day) - 1) AS metric_time__extract_dow + , EXTRACT(dayofyear FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql index e116ec9d20..686d0bb018 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - EXTRACT(DAYOFWEEK_ISO FROM subq_7.metric_time__day) AS metric_time__extract_dow + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql index cc185946bc..c2f5365be1 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql index fd9c20c355..61503885d9 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - CASE WHEN EXTRACT(dow FROM subq_7.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_7.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_7.metric_time__day) END AS metric_time__extract_dow + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , CASE WHEN EXTRACT(dow FROM subq_7.metric_time__day) = 0 THEN EXTRACT(dow FROM subq_7.metric_time__day) + 7 ELSE EXTRACT(dow FROM subq_7.metric_time__day) END AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql index c639ea1595..fb53d48b83 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - EXTRACT(dayofweekiso FROM subq_7.metric_time__day) AS metric_time__extract_dow + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(dayofweekiso FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql index 4e677bd7c1..6c7471d513 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql @@ -241,7 +241,17 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - EXTRACT(DAY_OF_WEEK FROM subq_7.metric_time__day) AS metric_time__extract_dow + subq_7.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week + , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month + , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter + , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year + , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter + , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month + , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day + , EXTRACT(DAY_OF_WEEK FROM subq_7.metric_time__day) AS metric_time__extract_dow + , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy , subq_6.ds__day AS ds__day , subq_6.ds__week AS ds__week , subq_6.ds__month AS ds__month diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/BigQuery/test_offset_to_grain_with_multiple_granularities__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/BigQuery/test_offset_to_grain_with_multiple_granularities__query_output.txt new file mode 100644 index 0000000000..8875d9a563 --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/BigQuery/test_offset_to_grain_with_multiple_granularities__query_output.txt @@ -0,0 +1,63 @@ + metric_time__day metric_time__month metric_time__year bookings_at_start_of_month +0 2019-12-01 2019-12-01 2019-01-01 1 +1 2019-12-02 2019-12-01 2019-01-01 1 +2 2019-12-03 2019-12-01 2019-01-01 1 +3 2019-12-04 2019-12-01 2019-01-01 1 +4 2019-12-05 2019-12-01 2019-01-01 1 +5 2019-12-06 2019-12-01 2019-01-01 1 +6 2019-12-07 2019-12-01 2019-01-01 1 +7 2019-12-08 2019-12-01 2019-01-01 1 +8 2019-12-09 2019-12-01 2019-01-01 1 +9 2019-12-10 2019-12-01 2019-01-01 1 +10 2019-12-11 2019-12-01 2019-01-01 1 +11 2019-12-12 2019-12-01 2019-01-01 1 +12 2019-12-13 2019-12-01 2019-01-01 1 +13 2019-12-14 2019-12-01 2019-01-01 1 +14 2019-12-15 2019-12-01 2019-01-01 1 +15 2019-12-16 2019-12-01 2019-01-01 1 +16 2019-12-17 2019-12-01 2019-01-01 1 +17 2019-12-18 2019-12-01 2019-01-01 1 +18 2019-12-19 2019-12-01 2019-01-01 1 +19 2019-12-20 2019-12-01 2019-01-01 1 +20 2019-12-21 2019-12-01 2019-01-01 1 +21 2019-12-22 2019-12-01 2019-01-01 1 +22 2019-12-23 2019-12-01 2019-01-01 1 +23 2019-12-24 2019-12-01 2019-01-01 1 +24 2019-12-25 2019-12-01 2019-01-01 1 +25 2019-12-26 2019-12-01 2019-01-01 1 +26 2019-12-27 2019-12-01 2019-01-01 1 +27 2019-12-28 2019-12-01 2019-01-01 1 +28 2019-12-29 2019-12-01 2019-01-01 1 +29 2019-12-30 2019-12-01 2019-01-01 1 +30 2019-12-31 2019-12-01 2019-01-01 1 +31 2020-01-01 2020-01-01 2020-01-01 5 +32 2020-01-02 2020-01-01 2020-01-01 5 +33 2020-01-03 2020-01-01 2020-01-01 5 +34 2020-01-04 2020-01-01 2020-01-01 5 +35 2020-01-05 2020-01-01 2020-01-01 5 +36 2020-01-06 2020-01-01 2020-01-01 5 +37 2020-01-07 2020-01-01 2020-01-01 5 +38 2020-01-08 2020-01-01 2020-01-01 5 +39 2020-01-09 2020-01-01 2020-01-01 5 +40 2020-01-10 2020-01-01 2020-01-01 5 +41 2020-01-11 2020-01-01 2020-01-01 5 +42 2020-01-12 2020-01-01 2020-01-01 5 +43 2020-01-13 2020-01-01 2020-01-01 5 +44 2020-01-14 2020-01-01 2020-01-01 5 +45 2020-01-15 2020-01-01 2020-01-01 5 +46 2020-01-16 2020-01-01 2020-01-01 5 +47 2020-01-17 2020-01-01 2020-01-01 5 +48 2020-01-18 2020-01-01 2020-01-01 5 +49 2020-01-19 2020-01-01 2020-01-01 5 +50 2020-01-20 2020-01-01 2020-01-01 5 +51 2020-01-21 2020-01-01 2020-01-01 5 +52 2020-01-22 2020-01-01 2020-01-01 5 +53 2020-01-23 2020-01-01 2020-01-01 5 +54 2020-01-24 2020-01-01 2020-01-01 5 +55 2020-01-25 2020-01-01 2020-01-01 5 +56 2020-01-26 2020-01-01 2020-01-01 5 +57 2020-01-27 2020-01-01 2020-01-01 5 +58 2020-01-28 2020-01-01 2020-01-01 5 +59 2020-01-29 2020-01-01 2020-01-01 5 +60 2020-01-30 2020-01-01 2020-01-01 5 +61 2020-01-31 2020-01-01 2020-01-01 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/BigQuery/test_offset_to_grain_with_single_granularity__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/BigQuery/test_offset_to_grain_with_single_granularity__query_output.txt new file mode 100644 index 0000000000..d339e19f8a --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/BigQuery/test_offset_to_grain_with_single_granularity__query_output.txt @@ -0,0 +1,63 @@ + metric_time__day bookings_at_start_of_month +0 2019-12-01 1 +1 2019-12-02 1 +2 2019-12-03 1 +3 2019-12-04 1 +4 2019-12-05 1 +5 2019-12-06 1 +6 2019-12-07 1 +7 2019-12-08 1 +8 2019-12-09 1 +9 2019-12-10 1 +10 2019-12-11 1 +11 2019-12-12 1 +12 2019-12-13 1 +13 2019-12-14 1 +14 2019-12-15 1 +15 2019-12-16 1 +16 2019-12-17 1 +17 2019-12-18 1 +18 2019-12-19 1 +19 2019-12-20 1 +20 2019-12-21 1 +21 2019-12-22 1 +22 2019-12-23 1 +23 2019-12-24 1 +24 2019-12-25 1 +25 2019-12-26 1 +26 2019-12-27 1 +27 2019-12-28 1 +28 2019-12-29 1 +29 2019-12-30 1 +30 2019-12-31 1 +31 2020-01-01 5 +32 2020-01-02 5 +33 2020-01-03 5 +34 2020-01-04 5 +35 2020-01-05 5 +36 2020-01-06 5 +37 2020-01-07 5 +38 2020-01-08 5 +39 2020-01-09 5 +40 2020-01-10 5 +41 2020-01-11 5 +42 2020-01-12 5 +43 2020-01-13 5 +44 2020-01-14 5 +45 2020-01-15 5 +46 2020-01-16 5 +47 2020-01-17 5 +48 2020-01-18 5 +49 2020-01-19 5 +50 2020-01-20 5 +51 2020-01-21 5 +52 2020-01-22 5 +53 2020-01-23 5 +54 2020-01-24 5 +55 2020-01-25 5 +56 2020-01-26 5 +57 2020-01-27 5 +58 2020-01-28 5 +59 2020-01-29 5 +60 2020-01-30 5 +61 2020-01-31 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/Databricks/test_offset_to_grain_with_multiple_granularities__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/Databricks/test_offset_to_grain_with_multiple_granularities__query_output.txt new file mode 100644 index 0000000000..2fc79193f7 --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/Databricks/test_offset_to_grain_with_multiple_granularities__query_output.txt @@ -0,0 +1,63 @@ + metric_time__day metric_time__month metric_time__year bookings_at_start_of_month +0 2019-12-01 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +1 2019-12-02 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +2 2019-12-03 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +3 2019-12-04 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +4 2019-12-05 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +5 2019-12-06 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +6 2019-12-07 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +7 2019-12-08 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +8 2019-12-09 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +9 2019-12-10 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +10 2019-12-11 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +11 2019-12-12 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +12 2019-12-13 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +13 2019-12-14 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +14 2019-12-15 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +15 2019-12-16 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +16 2019-12-17 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +17 2019-12-18 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +18 2019-12-19 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +19 2019-12-20 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +20 2019-12-21 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +21 2019-12-22 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +22 2019-12-23 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +23 2019-12-24 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +24 2019-12-25 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +25 2019-12-26 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +26 2019-12-27 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +27 2019-12-28 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +28 2019-12-29 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +29 2019-12-30 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +30 2019-12-31 00:00:00+00:00 2019-12-01 00:00:00+00:00 2019-01-01 00:00:00+00:00 1 +31 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +32 2020-01-02 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +33 2020-01-03 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +34 2020-01-04 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +35 2020-01-05 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +36 2020-01-06 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +37 2020-01-07 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +38 2020-01-08 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +39 2020-01-09 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +40 2020-01-10 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +41 2020-01-11 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +42 2020-01-12 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +43 2020-01-13 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +44 2020-01-14 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +45 2020-01-15 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +46 2020-01-16 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +47 2020-01-17 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +48 2020-01-18 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +49 2020-01-19 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +50 2020-01-20 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +51 2020-01-21 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +52 2020-01-22 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +53 2020-01-23 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +54 2020-01-24 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +55 2020-01-25 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +56 2020-01-26 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +57 2020-01-27 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +58 2020-01-28 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +59 2020-01-29 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +60 2020-01-30 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 +61 2020-01-31 00:00:00+00:00 2020-01-01 00:00:00+00:00 2020-01-01 00:00:00+00:00 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/Databricks/test_offset_to_grain_with_single_granularity__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/Databricks/test_offset_to_grain_with_single_granularity__query_output.txt new file mode 100644 index 0000000000..0a53d0d5d8 --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/Databricks/test_offset_to_grain_with_single_granularity__query_output.txt @@ -0,0 +1,63 @@ + metric_time__day bookings_at_start_of_month +0 2019-12-01 00:00:00+00:00 1 +1 2019-12-02 00:00:00+00:00 1 +2 2019-12-03 00:00:00+00:00 1 +3 2019-12-04 00:00:00+00:00 1 +4 2019-12-05 00:00:00+00:00 1 +5 2019-12-06 00:00:00+00:00 1 +6 2019-12-07 00:00:00+00:00 1 +7 2019-12-08 00:00:00+00:00 1 +8 2019-12-09 00:00:00+00:00 1 +9 2019-12-10 00:00:00+00:00 1 +10 2019-12-11 00:00:00+00:00 1 +11 2019-12-12 00:00:00+00:00 1 +12 2019-12-13 00:00:00+00:00 1 +13 2019-12-14 00:00:00+00:00 1 +14 2019-12-15 00:00:00+00:00 1 +15 2019-12-16 00:00:00+00:00 1 +16 2019-12-17 00:00:00+00:00 1 +17 2019-12-18 00:00:00+00:00 1 +18 2019-12-19 00:00:00+00:00 1 +19 2019-12-20 00:00:00+00:00 1 +20 2019-12-21 00:00:00+00:00 1 +21 2019-12-22 00:00:00+00:00 1 +22 2019-12-23 00:00:00+00:00 1 +23 2019-12-24 00:00:00+00:00 1 +24 2019-12-25 00:00:00+00:00 1 +25 2019-12-26 00:00:00+00:00 1 +26 2019-12-27 00:00:00+00:00 1 +27 2019-12-28 00:00:00+00:00 1 +28 2019-12-29 00:00:00+00:00 1 +29 2019-12-30 00:00:00+00:00 1 +30 2019-12-31 00:00:00+00:00 1 +31 2020-01-01 00:00:00+00:00 5 +32 2020-01-02 00:00:00+00:00 5 +33 2020-01-03 00:00:00+00:00 5 +34 2020-01-04 00:00:00+00:00 5 +35 2020-01-05 00:00:00+00:00 5 +36 2020-01-06 00:00:00+00:00 5 +37 2020-01-07 00:00:00+00:00 5 +38 2020-01-08 00:00:00+00:00 5 +39 2020-01-09 00:00:00+00:00 5 +40 2020-01-10 00:00:00+00:00 5 +41 2020-01-11 00:00:00+00:00 5 +42 2020-01-12 00:00:00+00:00 5 +43 2020-01-13 00:00:00+00:00 5 +44 2020-01-14 00:00:00+00:00 5 +45 2020-01-15 00:00:00+00:00 5 +46 2020-01-16 00:00:00+00:00 5 +47 2020-01-17 00:00:00+00:00 5 +48 2020-01-18 00:00:00+00:00 5 +49 2020-01-19 00:00:00+00:00 5 +50 2020-01-20 00:00:00+00:00 5 +51 2020-01-21 00:00:00+00:00 5 +52 2020-01-22 00:00:00+00:00 5 +53 2020-01-23 00:00:00+00:00 5 +54 2020-01-24 00:00:00+00:00 5 +55 2020-01-25 00:00:00+00:00 5 +56 2020-01-26 00:00:00+00:00 5 +57 2020-01-27 00:00:00+00:00 5 +58 2020-01-28 00:00:00+00:00 5 +59 2020-01-29 00:00:00+00:00 5 +60 2020-01-30 00:00:00+00:00 5 +61 2020-01-31 00:00:00+00:00 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt index 3439f21203..8875d9a563 100644 --- a/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_multiple_granularities__query_output.txt @@ -1,63 +1,63 @@ metric_time__day metric_time__month metric_time__year bookings_at_start_of_month -0 2019-12-02 2019-12-01 2019-01-01 1 -1 2019-12-07 2019-12-01 2019-01-01 1 -2 2019-12-24 2019-12-01 2019-01-01 1 -3 2020-01-08 2020-01-01 2020-01-01 5 -4 2020-01-26 2020-01-01 2020-01-01 5 -5 2019-12-18 2019-12-01 2019-01-01 1 -6 2019-12-19 2019-12-01 2019-01-01 1 -7 2019-12-20 2019-12-01 2019-01-01 1 -8 2020-01-06 2020-01-01 2020-01-01 5 -9 2020-01-25 2020-01-01 2020-01-01 5 -10 2019-12-22 2019-12-01 2019-01-01 1 -11 2019-12-23 2019-12-01 2019-01-01 1 -12 2019-12-26 2019-12-01 2019-01-01 1 -13 2019-12-30 2019-12-01 2019-01-01 1 -14 2019-12-31 2019-12-01 2019-01-01 1 -15 2020-01-04 2020-01-01 2020-01-01 5 -16 2020-01-11 2020-01-01 2020-01-01 5 -17 2020-01-14 2020-01-01 2020-01-01 5 -18 2020-01-15 2020-01-01 2020-01-01 5 -19 2020-01-16 2020-01-01 2020-01-01 5 -20 2020-01-22 2020-01-01 2020-01-01 5 -21 2019-12-03 2019-12-01 2019-01-01 1 -22 2019-12-13 2019-12-01 2019-01-01 1 -23 2019-12-14 2019-12-01 2019-01-01 1 -24 2019-12-15 2019-12-01 2019-01-01 1 -25 2019-12-27 2019-12-01 2019-01-01 1 -26 2020-01-03 2020-01-01 2020-01-01 5 -27 2019-12-25 2019-12-01 2019-01-01 1 -28 2020-01-05 2020-01-01 2020-01-01 5 -29 2020-01-13 2020-01-01 2020-01-01 5 -30 2020-01-19 2020-01-01 2020-01-01 5 -31 2020-01-27 2020-01-01 2020-01-01 5 -32 2019-12-01 2019-12-01 2019-01-01 1 -33 2019-12-08 2019-12-01 2019-01-01 1 -34 2019-12-11 2019-12-01 2019-01-01 1 -35 2019-12-21 2019-12-01 2019-01-01 1 -36 2020-01-07 2020-01-01 2020-01-01 5 -37 2020-01-09 2020-01-01 2020-01-01 5 -38 2020-01-18 2020-01-01 2020-01-01 5 -39 2020-01-21 2020-01-01 2020-01-01 5 -40 2020-01-24 2020-01-01 2020-01-01 5 -41 2020-01-29 2020-01-01 2020-01-01 5 -42 2020-01-30 2020-01-01 2020-01-01 5 -43 2020-01-31 2020-01-01 2020-01-01 5 -44 2019-12-06 2019-12-01 2019-01-01 1 -45 2019-12-09 2019-12-01 2019-01-01 1 -46 2019-12-12 2019-12-01 2019-01-01 1 -47 2019-12-16 2019-12-01 2019-01-01 1 -48 2019-12-17 2019-12-01 2019-01-01 1 -49 2020-01-01 2020-01-01 2020-01-01 5 -50 2020-01-02 2020-01-01 2020-01-01 5 -51 2020-01-10 2020-01-01 2020-01-01 5 -52 2020-01-17 2020-01-01 2020-01-01 5 -53 2020-01-20 2020-01-01 2020-01-01 5 -54 2020-01-28 2020-01-01 2020-01-01 5 -55 2019-12-04 2019-12-01 2019-01-01 1 -56 2019-12-05 2019-12-01 2019-01-01 1 -57 2019-12-10 2019-12-01 2019-01-01 1 -58 2019-12-28 2019-12-01 2019-01-01 1 -59 2019-12-29 2019-12-01 2019-01-01 1 -60 2020-01-12 2020-01-01 2020-01-01 5 -61 2020-01-23 2020-01-01 2020-01-01 5 +0 2019-12-01 2019-12-01 2019-01-01 1 +1 2019-12-02 2019-12-01 2019-01-01 1 +2 2019-12-03 2019-12-01 2019-01-01 1 +3 2019-12-04 2019-12-01 2019-01-01 1 +4 2019-12-05 2019-12-01 2019-01-01 1 +5 2019-12-06 2019-12-01 2019-01-01 1 +6 2019-12-07 2019-12-01 2019-01-01 1 +7 2019-12-08 2019-12-01 2019-01-01 1 +8 2019-12-09 2019-12-01 2019-01-01 1 +9 2019-12-10 2019-12-01 2019-01-01 1 +10 2019-12-11 2019-12-01 2019-01-01 1 +11 2019-12-12 2019-12-01 2019-01-01 1 +12 2019-12-13 2019-12-01 2019-01-01 1 +13 2019-12-14 2019-12-01 2019-01-01 1 +14 2019-12-15 2019-12-01 2019-01-01 1 +15 2019-12-16 2019-12-01 2019-01-01 1 +16 2019-12-17 2019-12-01 2019-01-01 1 +17 2019-12-18 2019-12-01 2019-01-01 1 +18 2019-12-19 2019-12-01 2019-01-01 1 +19 2019-12-20 2019-12-01 2019-01-01 1 +20 2019-12-21 2019-12-01 2019-01-01 1 +21 2019-12-22 2019-12-01 2019-01-01 1 +22 2019-12-23 2019-12-01 2019-01-01 1 +23 2019-12-24 2019-12-01 2019-01-01 1 +24 2019-12-25 2019-12-01 2019-01-01 1 +25 2019-12-26 2019-12-01 2019-01-01 1 +26 2019-12-27 2019-12-01 2019-01-01 1 +27 2019-12-28 2019-12-01 2019-01-01 1 +28 2019-12-29 2019-12-01 2019-01-01 1 +29 2019-12-30 2019-12-01 2019-01-01 1 +30 2019-12-31 2019-12-01 2019-01-01 1 +31 2020-01-01 2020-01-01 2020-01-01 5 +32 2020-01-02 2020-01-01 2020-01-01 5 +33 2020-01-03 2020-01-01 2020-01-01 5 +34 2020-01-04 2020-01-01 2020-01-01 5 +35 2020-01-05 2020-01-01 2020-01-01 5 +36 2020-01-06 2020-01-01 2020-01-01 5 +37 2020-01-07 2020-01-01 2020-01-01 5 +38 2020-01-08 2020-01-01 2020-01-01 5 +39 2020-01-09 2020-01-01 2020-01-01 5 +40 2020-01-10 2020-01-01 2020-01-01 5 +41 2020-01-11 2020-01-01 2020-01-01 5 +42 2020-01-12 2020-01-01 2020-01-01 5 +43 2020-01-13 2020-01-01 2020-01-01 5 +44 2020-01-14 2020-01-01 2020-01-01 5 +45 2020-01-15 2020-01-01 2020-01-01 5 +46 2020-01-16 2020-01-01 2020-01-01 5 +47 2020-01-17 2020-01-01 2020-01-01 5 +48 2020-01-18 2020-01-01 2020-01-01 5 +49 2020-01-19 2020-01-01 2020-01-01 5 +50 2020-01-20 2020-01-01 2020-01-01 5 +51 2020-01-21 2020-01-01 2020-01-01 5 +52 2020-01-22 2020-01-01 2020-01-01 5 +53 2020-01-23 2020-01-01 2020-01-01 5 +54 2020-01-24 2020-01-01 2020-01-01 5 +55 2020-01-25 2020-01-01 2020-01-01 5 +56 2020-01-26 2020-01-01 2020-01-01 5 +57 2020-01-27 2020-01-01 2020-01-01 5 +58 2020-01-28 2020-01-01 2020-01-01 5 +59 2020-01-29 2020-01-01 2020-01-01 5 +60 2020-01-30 2020-01-01 2020-01-01 5 +61 2020-01-31 2020-01-01 2020-01-01 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_single_granularity__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_single_granularity__query_output.txt index b90b143ca9..d339e19f8a 100644 --- a/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_single_granularity__query_output.txt +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/DuckDB/test_offset_to_grain_with_single_granularity__query_output.txt @@ -1,63 +1,63 @@ metric_time__day bookings_at_start_of_month -0 2019-12-06 1 -1 2019-12-09 1 -2 2019-12-16 1 -3 2019-12-19 1 -4 2020-01-28 5 -5 2019-12-10 1 -6 2019-12-11 1 -7 2019-12-24 1 -8 2019-12-31 1 -9 2020-01-02 5 -10 2020-01-11 5 -11 2020-01-22 5 -12 2019-12-03 1 -13 2019-12-17 1 -14 2019-12-18 1 -15 2019-12-23 1 -16 2019-12-26 1 -17 2019-12-27 1 -18 2020-01-10 5 -19 2020-01-24 5 -20 2020-01-25 5 -21 2019-12-01 1 -22 2019-12-05 1 -23 2019-12-14 1 -24 2020-01-01 5 -25 2020-01-05 5 -26 2020-01-08 5 -27 2020-01-16 5 -28 2020-01-18 5 -29 2020-01-29 5 -30 2019-12-04 1 -31 2019-12-12 1 -32 2019-12-21 1 -33 2019-12-25 1 -34 2019-12-28 1 -35 2019-12-30 1 -36 2020-01-09 5 -37 2020-01-13 5 -38 2020-01-20 5 -39 2020-01-27 5 -40 2019-12-02 1 -41 2019-12-13 1 -42 2019-12-20 1 -43 2020-01-03 5 -44 2020-01-06 5 -45 2020-01-07 5 -46 2020-01-14 5 -47 2020-01-15 5 -48 2020-01-21 5 -49 2020-01-23 5 -50 2020-01-26 5 -51 2020-01-31 5 -52 2019-12-07 1 -53 2019-12-29 1 -54 2020-01-12 5 -55 2019-12-08 1 -56 2019-12-15 1 -57 2019-12-22 1 -58 2020-01-04 5 -59 2020-01-17 5 -60 2020-01-19 5 -61 2020-01-30 5 +0 2019-12-01 1 +1 2019-12-02 1 +2 2019-12-03 1 +3 2019-12-04 1 +4 2019-12-05 1 +5 2019-12-06 1 +6 2019-12-07 1 +7 2019-12-08 1 +8 2019-12-09 1 +9 2019-12-10 1 +10 2019-12-11 1 +11 2019-12-12 1 +12 2019-12-13 1 +13 2019-12-14 1 +14 2019-12-15 1 +15 2019-12-16 1 +16 2019-12-17 1 +17 2019-12-18 1 +18 2019-12-19 1 +19 2019-12-20 1 +20 2019-12-21 1 +21 2019-12-22 1 +22 2019-12-23 1 +23 2019-12-24 1 +24 2019-12-25 1 +25 2019-12-26 1 +26 2019-12-27 1 +27 2019-12-28 1 +28 2019-12-29 1 +29 2019-12-30 1 +30 2019-12-31 1 +31 2020-01-01 5 +32 2020-01-02 5 +33 2020-01-03 5 +34 2020-01-04 5 +35 2020-01-05 5 +36 2020-01-06 5 +37 2020-01-07 5 +38 2020-01-08 5 +39 2020-01-09 5 +40 2020-01-10 5 +41 2020-01-11 5 +42 2020-01-12 5 +43 2020-01-13 5 +44 2020-01-14 5 +45 2020-01-15 5 +46 2020-01-16 5 +47 2020-01-17 5 +48 2020-01-18 5 +49 2020-01-19 5 +50 2020-01-20 5 +51 2020-01-21 5 +52 2020-01-22 5 +53 2020-01-23 5 +54 2020-01-24 5 +55 2020-01-25 5 +56 2020-01-26 5 +57 2020-01-27 5 +58 2020-01-28 5 +59 2020-01-29 5 +60 2020-01-30 5 +61 2020-01-31 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/Postgres/test_offset_to_grain_with_multiple_granularities__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/Postgres/test_offset_to_grain_with_multiple_granularities__query_output.txt new file mode 100644 index 0000000000..8875d9a563 --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/Postgres/test_offset_to_grain_with_multiple_granularities__query_output.txt @@ -0,0 +1,63 @@ + metric_time__day metric_time__month metric_time__year bookings_at_start_of_month +0 2019-12-01 2019-12-01 2019-01-01 1 +1 2019-12-02 2019-12-01 2019-01-01 1 +2 2019-12-03 2019-12-01 2019-01-01 1 +3 2019-12-04 2019-12-01 2019-01-01 1 +4 2019-12-05 2019-12-01 2019-01-01 1 +5 2019-12-06 2019-12-01 2019-01-01 1 +6 2019-12-07 2019-12-01 2019-01-01 1 +7 2019-12-08 2019-12-01 2019-01-01 1 +8 2019-12-09 2019-12-01 2019-01-01 1 +9 2019-12-10 2019-12-01 2019-01-01 1 +10 2019-12-11 2019-12-01 2019-01-01 1 +11 2019-12-12 2019-12-01 2019-01-01 1 +12 2019-12-13 2019-12-01 2019-01-01 1 +13 2019-12-14 2019-12-01 2019-01-01 1 +14 2019-12-15 2019-12-01 2019-01-01 1 +15 2019-12-16 2019-12-01 2019-01-01 1 +16 2019-12-17 2019-12-01 2019-01-01 1 +17 2019-12-18 2019-12-01 2019-01-01 1 +18 2019-12-19 2019-12-01 2019-01-01 1 +19 2019-12-20 2019-12-01 2019-01-01 1 +20 2019-12-21 2019-12-01 2019-01-01 1 +21 2019-12-22 2019-12-01 2019-01-01 1 +22 2019-12-23 2019-12-01 2019-01-01 1 +23 2019-12-24 2019-12-01 2019-01-01 1 +24 2019-12-25 2019-12-01 2019-01-01 1 +25 2019-12-26 2019-12-01 2019-01-01 1 +26 2019-12-27 2019-12-01 2019-01-01 1 +27 2019-12-28 2019-12-01 2019-01-01 1 +28 2019-12-29 2019-12-01 2019-01-01 1 +29 2019-12-30 2019-12-01 2019-01-01 1 +30 2019-12-31 2019-12-01 2019-01-01 1 +31 2020-01-01 2020-01-01 2020-01-01 5 +32 2020-01-02 2020-01-01 2020-01-01 5 +33 2020-01-03 2020-01-01 2020-01-01 5 +34 2020-01-04 2020-01-01 2020-01-01 5 +35 2020-01-05 2020-01-01 2020-01-01 5 +36 2020-01-06 2020-01-01 2020-01-01 5 +37 2020-01-07 2020-01-01 2020-01-01 5 +38 2020-01-08 2020-01-01 2020-01-01 5 +39 2020-01-09 2020-01-01 2020-01-01 5 +40 2020-01-10 2020-01-01 2020-01-01 5 +41 2020-01-11 2020-01-01 2020-01-01 5 +42 2020-01-12 2020-01-01 2020-01-01 5 +43 2020-01-13 2020-01-01 2020-01-01 5 +44 2020-01-14 2020-01-01 2020-01-01 5 +45 2020-01-15 2020-01-01 2020-01-01 5 +46 2020-01-16 2020-01-01 2020-01-01 5 +47 2020-01-17 2020-01-01 2020-01-01 5 +48 2020-01-18 2020-01-01 2020-01-01 5 +49 2020-01-19 2020-01-01 2020-01-01 5 +50 2020-01-20 2020-01-01 2020-01-01 5 +51 2020-01-21 2020-01-01 2020-01-01 5 +52 2020-01-22 2020-01-01 2020-01-01 5 +53 2020-01-23 2020-01-01 2020-01-01 5 +54 2020-01-24 2020-01-01 2020-01-01 5 +55 2020-01-25 2020-01-01 2020-01-01 5 +56 2020-01-26 2020-01-01 2020-01-01 5 +57 2020-01-27 2020-01-01 2020-01-01 5 +58 2020-01-28 2020-01-01 2020-01-01 5 +59 2020-01-29 2020-01-01 2020-01-01 5 +60 2020-01-30 2020-01-01 2020-01-01 5 +61 2020-01-31 2020-01-01 2020-01-01 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/Postgres/test_offset_to_grain_with_single_granularity__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/Postgres/test_offset_to_grain_with_single_granularity__query_output.txt new file mode 100644 index 0000000000..d339e19f8a --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/Postgres/test_offset_to_grain_with_single_granularity__query_output.txt @@ -0,0 +1,63 @@ + metric_time__day bookings_at_start_of_month +0 2019-12-01 1 +1 2019-12-02 1 +2 2019-12-03 1 +3 2019-12-04 1 +4 2019-12-05 1 +5 2019-12-06 1 +6 2019-12-07 1 +7 2019-12-08 1 +8 2019-12-09 1 +9 2019-12-10 1 +10 2019-12-11 1 +11 2019-12-12 1 +12 2019-12-13 1 +13 2019-12-14 1 +14 2019-12-15 1 +15 2019-12-16 1 +16 2019-12-17 1 +17 2019-12-18 1 +18 2019-12-19 1 +19 2019-12-20 1 +20 2019-12-21 1 +21 2019-12-22 1 +22 2019-12-23 1 +23 2019-12-24 1 +24 2019-12-25 1 +25 2019-12-26 1 +26 2019-12-27 1 +27 2019-12-28 1 +28 2019-12-29 1 +29 2019-12-30 1 +30 2019-12-31 1 +31 2020-01-01 5 +32 2020-01-02 5 +33 2020-01-03 5 +34 2020-01-04 5 +35 2020-01-05 5 +36 2020-01-06 5 +37 2020-01-07 5 +38 2020-01-08 5 +39 2020-01-09 5 +40 2020-01-10 5 +41 2020-01-11 5 +42 2020-01-12 5 +43 2020-01-13 5 +44 2020-01-14 5 +45 2020-01-15 5 +46 2020-01-16 5 +47 2020-01-17 5 +48 2020-01-18 5 +49 2020-01-19 5 +50 2020-01-20 5 +51 2020-01-21 5 +52 2020-01-22 5 +53 2020-01-23 5 +54 2020-01-24 5 +55 2020-01-25 5 +56 2020-01-26 5 +57 2020-01-27 5 +58 2020-01-28 5 +59 2020-01-29 5 +60 2020-01-30 5 +61 2020-01-31 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/Redshift/test_offset_to_grain_with_multiple_granularities__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/Redshift/test_offset_to_grain_with_multiple_granularities__query_output.txt new file mode 100644 index 0000000000..8875d9a563 --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/Redshift/test_offset_to_grain_with_multiple_granularities__query_output.txt @@ -0,0 +1,63 @@ + metric_time__day metric_time__month metric_time__year bookings_at_start_of_month +0 2019-12-01 2019-12-01 2019-01-01 1 +1 2019-12-02 2019-12-01 2019-01-01 1 +2 2019-12-03 2019-12-01 2019-01-01 1 +3 2019-12-04 2019-12-01 2019-01-01 1 +4 2019-12-05 2019-12-01 2019-01-01 1 +5 2019-12-06 2019-12-01 2019-01-01 1 +6 2019-12-07 2019-12-01 2019-01-01 1 +7 2019-12-08 2019-12-01 2019-01-01 1 +8 2019-12-09 2019-12-01 2019-01-01 1 +9 2019-12-10 2019-12-01 2019-01-01 1 +10 2019-12-11 2019-12-01 2019-01-01 1 +11 2019-12-12 2019-12-01 2019-01-01 1 +12 2019-12-13 2019-12-01 2019-01-01 1 +13 2019-12-14 2019-12-01 2019-01-01 1 +14 2019-12-15 2019-12-01 2019-01-01 1 +15 2019-12-16 2019-12-01 2019-01-01 1 +16 2019-12-17 2019-12-01 2019-01-01 1 +17 2019-12-18 2019-12-01 2019-01-01 1 +18 2019-12-19 2019-12-01 2019-01-01 1 +19 2019-12-20 2019-12-01 2019-01-01 1 +20 2019-12-21 2019-12-01 2019-01-01 1 +21 2019-12-22 2019-12-01 2019-01-01 1 +22 2019-12-23 2019-12-01 2019-01-01 1 +23 2019-12-24 2019-12-01 2019-01-01 1 +24 2019-12-25 2019-12-01 2019-01-01 1 +25 2019-12-26 2019-12-01 2019-01-01 1 +26 2019-12-27 2019-12-01 2019-01-01 1 +27 2019-12-28 2019-12-01 2019-01-01 1 +28 2019-12-29 2019-12-01 2019-01-01 1 +29 2019-12-30 2019-12-01 2019-01-01 1 +30 2019-12-31 2019-12-01 2019-01-01 1 +31 2020-01-01 2020-01-01 2020-01-01 5 +32 2020-01-02 2020-01-01 2020-01-01 5 +33 2020-01-03 2020-01-01 2020-01-01 5 +34 2020-01-04 2020-01-01 2020-01-01 5 +35 2020-01-05 2020-01-01 2020-01-01 5 +36 2020-01-06 2020-01-01 2020-01-01 5 +37 2020-01-07 2020-01-01 2020-01-01 5 +38 2020-01-08 2020-01-01 2020-01-01 5 +39 2020-01-09 2020-01-01 2020-01-01 5 +40 2020-01-10 2020-01-01 2020-01-01 5 +41 2020-01-11 2020-01-01 2020-01-01 5 +42 2020-01-12 2020-01-01 2020-01-01 5 +43 2020-01-13 2020-01-01 2020-01-01 5 +44 2020-01-14 2020-01-01 2020-01-01 5 +45 2020-01-15 2020-01-01 2020-01-01 5 +46 2020-01-16 2020-01-01 2020-01-01 5 +47 2020-01-17 2020-01-01 2020-01-01 5 +48 2020-01-18 2020-01-01 2020-01-01 5 +49 2020-01-19 2020-01-01 2020-01-01 5 +50 2020-01-20 2020-01-01 2020-01-01 5 +51 2020-01-21 2020-01-01 2020-01-01 5 +52 2020-01-22 2020-01-01 2020-01-01 5 +53 2020-01-23 2020-01-01 2020-01-01 5 +54 2020-01-24 2020-01-01 2020-01-01 5 +55 2020-01-25 2020-01-01 2020-01-01 5 +56 2020-01-26 2020-01-01 2020-01-01 5 +57 2020-01-27 2020-01-01 2020-01-01 5 +58 2020-01-28 2020-01-01 2020-01-01 5 +59 2020-01-29 2020-01-01 2020-01-01 5 +60 2020-01-30 2020-01-01 2020-01-01 5 +61 2020-01-31 2020-01-01 2020-01-01 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/Redshift/test_offset_to_grain_with_single_granularity__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/Redshift/test_offset_to_grain_with_single_granularity__query_output.txt new file mode 100644 index 0000000000..d339e19f8a --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/Redshift/test_offset_to_grain_with_single_granularity__query_output.txt @@ -0,0 +1,63 @@ + metric_time__day bookings_at_start_of_month +0 2019-12-01 1 +1 2019-12-02 1 +2 2019-12-03 1 +3 2019-12-04 1 +4 2019-12-05 1 +5 2019-12-06 1 +6 2019-12-07 1 +7 2019-12-08 1 +8 2019-12-09 1 +9 2019-12-10 1 +10 2019-12-11 1 +11 2019-12-12 1 +12 2019-12-13 1 +13 2019-12-14 1 +14 2019-12-15 1 +15 2019-12-16 1 +16 2019-12-17 1 +17 2019-12-18 1 +18 2019-12-19 1 +19 2019-12-20 1 +20 2019-12-21 1 +21 2019-12-22 1 +22 2019-12-23 1 +23 2019-12-24 1 +24 2019-12-25 1 +25 2019-12-26 1 +26 2019-12-27 1 +27 2019-12-28 1 +28 2019-12-29 1 +29 2019-12-30 1 +30 2019-12-31 1 +31 2020-01-01 5 +32 2020-01-02 5 +33 2020-01-03 5 +34 2020-01-04 5 +35 2020-01-05 5 +36 2020-01-06 5 +37 2020-01-07 5 +38 2020-01-08 5 +39 2020-01-09 5 +40 2020-01-10 5 +41 2020-01-11 5 +42 2020-01-12 5 +43 2020-01-13 5 +44 2020-01-14 5 +45 2020-01-15 5 +46 2020-01-16 5 +47 2020-01-17 5 +48 2020-01-18 5 +49 2020-01-19 5 +50 2020-01-20 5 +51 2020-01-21 5 +52 2020-01-22 5 +53 2020-01-23 5 +54 2020-01-24 5 +55 2020-01-25 5 +56 2020-01-26 5 +57 2020-01-27 5 +58 2020-01-28 5 +59 2020-01-29 5 +60 2020-01-30 5 +61 2020-01-31 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/Snowflake/test_offset_to_grain_with_multiple_granularities__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/Snowflake/test_offset_to_grain_with_multiple_granularities__query_output.txt new file mode 100644 index 0000000000..ba72aba37c --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/Snowflake/test_offset_to_grain_with_multiple_granularities__query_output.txt @@ -0,0 +1,63 @@ + METRIC_TIME__DAY METRIC_TIME__MONTH METRIC_TIME__YEAR BOOKINGS_AT_START_OF_MONTH +0 2019-12-01 2019-12-01 2019-01-01 1 +1 2019-12-02 2019-12-01 2019-01-01 1 +2 2019-12-03 2019-12-01 2019-01-01 1 +3 2019-12-04 2019-12-01 2019-01-01 1 +4 2019-12-05 2019-12-01 2019-01-01 1 +5 2019-12-06 2019-12-01 2019-01-01 1 +6 2019-12-07 2019-12-01 2019-01-01 1 +7 2019-12-08 2019-12-01 2019-01-01 1 +8 2019-12-09 2019-12-01 2019-01-01 1 +9 2019-12-10 2019-12-01 2019-01-01 1 +10 2019-12-11 2019-12-01 2019-01-01 1 +11 2019-12-12 2019-12-01 2019-01-01 1 +12 2019-12-13 2019-12-01 2019-01-01 1 +13 2019-12-14 2019-12-01 2019-01-01 1 +14 2019-12-15 2019-12-01 2019-01-01 1 +15 2019-12-16 2019-12-01 2019-01-01 1 +16 2019-12-17 2019-12-01 2019-01-01 1 +17 2019-12-18 2019-12-01 2019-01-01 1 +18 2019-12-19 2019-12-01 2019-01-01 1 +19 2019-12-20 2019-12-01 2019-01-01 1 +20 2019-12-21 2019-12-01 2019-01-01 1 +21 2019-12-22 2019-12-01 2019-01-01 1 +22 2019-12-23 2019-12-01 2019-01-01 1 +23 2019-12-24 2019-12-01 2019-01-01 1 +24 2019-12-25 2019-12-01 2019-01-01 1 +25 2019-12-26 2019-12-01 2019-01-01 1 +26 2019-12-27 2019-12-01 2019-01-01 1 +27 2019-12-28 2019-12-01 2019-01-01 1 +28 2019-12-29 2019-12-01 2019-01-01 1 +29 2019-12-30 2019-12-01 2019-01-01 1 +30 2019-12-31 2019-12-01 2019-01-01 1 +31 2020-01-01 2020-01-01 2020-01-01 5 +32 2020-01-02 2020-01-01 2020-01-01 5 +33 2020-01-03 2020-01-01 2020-01-01 5 +34 2020-01-04 2020-01-01 2020-01-01 5 +35 2020-01-05 2020-01-01 2020-01-01 5 +36 2020-01-06 2020-01-01 2020-01-01 5 +37 2020-01-07 2020-01-01 2020-01-01 5 +38 2020-01-08 2020-01-01 2020-01-01 5 +39 2020-01-09 2020-01-01 2020-01-01 5 +40 2020-01-10 2020-01-01 2020-01-01 5 +41 2020-01-11 2020-01-01 2020-01-01 5 +42 2020-01-12 2020-01-01 2020-01-01 5 +43 2020-01-13 2020-01-01 2020-01-01 5 +44 2020-01-14 2020-01-01 2020-01-01 5 +45 2020-01-15 2020-01-01 2020-01-01 5 +46 2020-01-16 2020-01-01 2020-01-01 5 +47 2020-01-17 2020-01-01 2020-01-01 5 +48 2020-01-18 2020-01-01 2020-01-01 5 +49 2020-01-19 2020-01-01 2020-01-01 5 +50 2020-01-20 2020-01-01 2020-01-01 5 +51 2020-01-21 2020-01-01 2020-01-01 5 +52 2020-01-22 2020-01-01 2020-01-01 5 +53 2020-01-23 2020-01-01 2020-01-01 5 +54 2020-01-24 2020-01-01 2020-01-01 5 +55 2020-01-25 2020-01-01 2020-01-01 5 +56 2020-01-26 2020-01-01 2020-01-01 5 +57 2020-01-27 2020-01-01 2020-01-01 5 +58 2020-01-28 2020-01-01 2020-01-01 5 +59 2020-01-29 2020-01-01 2020-01-01 5 +60 2020-01-30 2020-01-01 2020-01-01 5 +61 2020-01-31 2020-01-01 2020-01-01 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/Snowflake/test_offset_to_grain_with_single_granularity__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/Snowflake/test_offset_to_grain_with_single_granularity__query_output.txt new file mode 100644 index 0000000000..911eba604f --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/Snowflake/test_offset_to_grain_with_single_granularity__query_output.txt @@ -0,0 +1,63 @@ + METRIC_TIME__DAY BOOKINGS_AT_START_OF_MONTH +0 2019-12-01 1 +1 2019-12-02 1 +2 2019-12-03 1 +3 2019-12-04 1 +4 2019-12-05 1 +5 2019-12-06 1 +6 2019-12-07 1 +7 2019-12-08 1 +8 2019-12-09 1 +9 2019-12-10 1 +10 2019-12-11 1 +11 2019-12-12 1 +12 2019-12-13 1 +13 2019-12-14 1 +14 2019-12-15 1 +15 2019-12-16 1 +16 2019-12-17 1 +17 2019-12-18 1 +18 2019-12-19 1 +19 2019-12-20 1 +20 2019-12-21 1 +21 2019-12-22 1 +22 2019-12-23 1 +23 2019-12-24 1 +24 2019-12-25 1 +25 2019-12-26 1 +26 2019-12-27 1 +27 2019-12-28 1 +28 2019-12-29 1 +29 2019-12-30 1 +30 2019-12-31 1 +31 2020-01-01 5 +32 2020-01-02 5 +33 2020-01-03 5 +34 2020-01-04 5 +35 2020-01-05 5 +36 2020-01-06 5 +37 2020-01-07 5 +38 2020-01-08 5 +39 2020-01-09 5 +40 2020-01-10 5 +41 2020-01-11 5 +42 2020-01-12 5 +43 2020-01-13 5 +44 2020-01-14 5 +45 2020-01-15 5 +46 2020-01-16 5 +47 2020-01-17 5 +48 2020-01-18 5 +49 2020-01-19 5 +50 2020-01-20 5 +51 2020-01-21 5 +52 2020-01-22 5 +53 2020-01-23 5 +54 2020-01-24 5 +55 2020-01-25 5 +56 2020-01-26 5 +57 2020-01-27 5 +58 2020-01-28 5 +59 2020-01-29 5 +60 2020-01-30 5 +61 2020-01-31 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/Trino/test_offset_to_grain_with_multiple_granularities__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/Trino/test_offset_to_grain_with_multiple_granularities__query_output.txt new file mode 100644 index 0000000000..8875d9a563 --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/Trino/test_offset_to_grain_with_multiple_granularities__query_output.txt @@ -0,0 +1,63 @@ + metric_time__day metric_time__month metric_time__year bookings_at_start_of_month +0 2019-12-01 2019-12-01 2019-01-01 1 +1 2019-12-02 2019-12-01 2019-01-01 1 +2 2019-12-03 2019-12-01 2019-01-01 1 +3 2019-12-04 2019-12-01 2019-01-01 1 +4 2019-12-05 2019-12-01 2019-01-01 1 +5 2019-12-06 2019-12-01 2019-01-01 1 +6 2019-12-07 2019-12-01 2019-01-01 1 +7 2019-12-08 2019-12-01 2019-01-01 1 +8 2019-12-09 2019-12-01 2019-01-01 1 +9 2019-12-10 2019-12-01 2019-01-01 1 +10 2019-12-11 2019-12-01 2019-01-01 1 +11 2019-12-12 2019-12-01 2019-01-01 1 +12 2019-12-13 2019-12-01 2019-01-01 1 +13 2019-12-14 2019-12-01 2019-01-01 1 +14 2019-12-15 2019-12-01 2019-01-01 1 +15 2019-12-16 2019-12-01 2019-01-01 1 +16 2019-12-17 2019-12-01 2019-01-01 1 +17 2019-12-18 2019-12-01 2019-01-01 1 +18 2019-12-19 2019-12-01 2019-01-01 1 +19 2019-12-20 2019-12-01 2019-01-01 1 +20 2019-12-21 2019-12-01 2019-01-01 1 +21 2019-12-22 2019-12-01 2019-01-01 1 +22 2019-12-23 2019-12-01 2019-01-01 1 +23 2019-12-24 2019-12-01 2019-01-01 1 +24 2019-12-25 2019-12-01 2019-01-01 1 +25 2019-12-26 2019-12-01 2019-01-01 1 +26 2019-12-27 2019-12-01 2019-01-01 1 +27 2019-12-28 2019-12-01 2019-01-01 1 +28 2019-12-29 2019-12-01 2019-01-01 1 +29 2019-12-30 2019-12-01 2019-01-01 1 +30 2019-12-31 2019-12-01 2019-01-01 1 +31 2020-01-01 2020-01-01 2020-01-01 5 +32 2020-01-02 2020-01-01 2020-01-01 5 +33 2020-01-03 2020-01-01 2020-01-01 5 +34 2020-01-04 2020-01-01 2020-01-01 5 +35 2020-01-05 2020-01-01 2020-01-01 5 +36 2020-01-06 2020-01-01 2020-01-01 5 +37 2020-01-07 2020-01-01 2020-01-01 5 +38 2020-01-08 2020-01-01 2020-01-01 5 +39 2020-01-09 2020-01-01 2020-01-01 5 +40 2020-01-10 2020-01-01 2020-01-01 5 +41 2020-01-11 2020-01-01 2020-01-01 5 +42 2020-01-12 2020-01-01 2020-01-01 5 +43 2020-01-13 2020-01-01 2020-01-01 5 +44 2020-01-14 2020-01-01 2020-01-01 5 +45 2020-01-15 2020-01-01 2020-01-01 5 +46 2020-01-16 2020-01-01 2020-01-01 5 +47 2020-01-17 2020-01-01 2020-01-01 5 +48 2020-01-18 2020-01-01 2020-01-01 5 +49 2020-01-19 2020-01-01 2020-01-01 5 +50 2020-01-20 2020-01-01 2020-01-01 5 +51 2020-01-21 2020-01-01 2020-01-01 5 +52 2020-01-22 2020-01-01 2020-01-01 5 +53 2020-01-23 2020-01-01 2020-01-01 5 +54 2020-01-24 2020-01-01 2020-01-01 5 +55 2020-01-25 2020-01-01 2020-01-01 5 +56 2020-01-26 2020-01-01 2020-01-01 5 +57 2020-01-27 2020-01-01 2020-01-01 5 +58 2020-01-28 2020-01-01 2020-01-01 5 +59 2020-01-29 2020-01-01 2020-01-01 5 +60 2020-01-30 2020-01-01 2020-01-01 5 +61 2020-01-31 2020-01-01 2020-01-01 5 diff --git a/metricflow/test/snapshots/test_offset_metrics.py/str/Trino/test_offset_to_grain_with_single_granularity__query_output.txt b/metricflow/test/snapshots/test_offset_metrics.py/str/Trino/test_offset_to_grain_with_single_granularity__query_output.txt new file mode 100644 index 0000000000..d339e19f8a --- /dev/null +++ b/metricflow/test/snapshots/test_offset_metrics.py/str/Trino/test_offset_to_grain_with_single_granularity__query_output.txt @@ -0,0 +1,63 @@ + metric_time__day bookings_at_start_of_month +0 2019-12-01 1 +1 2019-12-02 1 +2 2019-12-03 1 +3 2019-12-04 1 +4 2019-12-05 1 +5 2019-12-06 1 +6 2019-12-07 1 +7 2019-12-08 1 +8 2019-12-09 1 +9 2019-12-10 1 +10 2019-12-11 1 +11 2019-12-12 1 +12 2019-12-13 1 +13 2019-12-14 1 +14 2019-12-15 1 +15 2019-12-16 1 +16 2019-12-17 1 +17 2019-12-18 1 +18 2019-12-19 1 +19 2019-12-20 1 +20 2019-12-21 1 +21 2019-12-22 1 +22 2019-12-23 1 +23 2019-12-24 1 +24 2019-12-25 1 +25 2019-12-26 1 +26 2019-12-27 1 +27 2019-12-28 1 +28 2019-12-29 1 +29 2019-12-30 1 +30 2019-12-31 1 +31 2020-01-01 5 +32 2020-01-02 5 +33 2020-01-03 5 +34 2020-01-04 5 +35 2020-01-05 5 +36 2020-01-06 5 +37 2020-01-07 5 +38 2020-01-08 5 +39 2020-01-09 5 +40 2020-01-10 5 +41 2020-01-11 5 +42 2020-01-12 5 +43 2020-01-13 5 +44 2020-01-14 5 +45 2020-01-15 5 +46 2020-01-16 5 +47 2020-01-17 5 +48 2020-01-18 5 +49 2020-01-19 5 +50 2020-01-20 5 +51 2020-01-21 5 +52 2020-01-22 5 +53 2020-01-23 5 +54 2020-01-24 5 +55 2020-01-25 5 +56 2020-01-26 5 +57 2020-01-27 5 +58 2020-01-28 5 +59 2020-01-29 5 +60 2020-01-30 5 +61 2020-01-31 5 From dc60c11e00907c798c9b5c25865b3949184c9aff Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 29 Feb 2024 09:40:01 -0800 Subject: [PATCH 7/8] Add assertion & fix variable name bug --- metricflow/plan_conversion/dataflow_to_sql.py | 52 ++++++++++++------- ...set_metric_with_time_constraint__plan0.sql | 2 +- ...nth_dimension_and_offset_window__plan0.sql | 2 +- ...ved_metric_with_offset_to_grain__plan0.sql | 2 +- ...offset_to_grain_and_granularity__plan0.sql | 2 +- ...rived_metric_with_offset_window__plan0.sql | 2 +- ...h_offset_window_and_granularity__plan0.sql | 2 +- ...fset_window_and_offset_to_grain__plan0.sql | 4 +- ...offset_to_grain_and_granularity__plan0.sql | 4 +- ...h_offset_window_and_time_filter__plan0.sql | 2 +- ...erived_offset_cumulative_metric__plan0.sql | 2 +- ...offset_metric_with_agg_time_dim__plan0.sql | 2 +- ...et_metric_with_one_input_metric__plan0.sql | 2 +- ...d_where_constraint_not_selected__plan0.sql | 2 +- .../DuckDB/test_nested_offsets__plan0.sql | 2 +- ...ed_offsets_with_time_constraint__plan0.sql | 2 +- ...d_offsets_with_where_constraint__plan0.sql | 2 +- ...ry_have_different_granularities__plan0.sql | 2 +- ...n_metric_multiple_granularities__plan0.sql | 2 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 2 +- ...ry_have_different_granularities__plan0.sql | 2 +- ...w_metric_multiple_granularities__plan0.sql | 2 +- ...offset_window_with_agg_time_dim__plan0.sql | 2 +- ...set_metric_with_time_constraint__plan0.sql | 2 +- ...fill_nulls_for_one_input_metric__plan0.sql | 2 +- ...st_offset_window_with_date_part__plan0.sql | 2 +- 26 files changed, 60 insertions(+), 46 deletions(-) diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index 47046c41e0..b4f6fc480d 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -216,19 +216,18 @@ def _make_time_spine_data_set( This is useful in computing cumulative metrics. This will need to be updated to support granularities finer than a day. """ - time_spine_instance = ( - TimeDimensionInstance( - defined_from=agg_time_dimension_instance.defined_from, - associated_columns=( - ColumnAssociation( - column_name=agg_time_dimension_column_name, - single_column_correlation_key=SingleColumnCorrelationKey(), - ), + time_spine_instance = TimeDimensionInstance( + defined_from=agg_time_dimension_instance.defined_from, + associated_columns=( + ColumnAssociation( + column_name=agg_time_dimension_column_name, + single_column_correlation_key=SingleColumnCorrelationKey(), ), - spec=agg_time_dimension_instance.spec, ), + spec=agg_time_dimension_instance.spec, ) - time_spine_instance_set = InstanceSet(time_dimension_instances=time_spine_instance) + + time_spine_instance_set = InstanceSet(time_dimension_instances=(time_spine_instance,)) time_spine_table_alias = self._next_unique_table_alias() # If the requested granularity is the same as the granularity of the spine, do a direct select. @@ -1334,11 +1333,13 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet len(time_spine_dataset.instance_set.time_dimension_instances) == 1 and len(time_spine_dataset.sql_select_node.select_columns) == 1 ), "Time spine dataset not configured properly. Expected exactly one column." - time_spine_dim_instance = time_spine_dataset.instance_set.time_dimension_instances[0] + original_time_spine_dim_instance = time_spine_dataset.instance_set.time_dimension_instances[0] time_spine_column_select_expr: Union[ SqlColumnReferenceExpression, SqlDateTruncExpression ] = SqlColumnReferenceExpression( - SqlColumnReference(table_alias=time_spine_alias, column_name=time_spine_dim_instance.spec.qualified_name) + SqlColumnReference( + table_alias=time_spine_alias, column_name=original_time_spine_dim_instance.spec.qualified_name + ) ) time_spine_select_columns = [] @@ -1348,17 +1349,30 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet # If offset_to_grain is used, will need to filter down to rows that match selected granularities. # Does not apply if one of the granularities selected matches the time spine column granularity. need_where_filter = ( - node.offset_to_grain and time_spine_dim_instance.spec not in node.requested_agg_time_dimension_specs + node.offset_to_grain + and original_time_spine_dim_instance.spec not in node.requested_agg_time_dimension_specs ) # Add requested granularities (if different from time_spine) and date_parts to time spine column. for time_dimension_instance in time_dimensions_to_select_from_time_spine: time_dimension_spec = time_dimension_instance.spec - # Apply grain to time spine column select expression, unless grain already matches time spine column. + # TODO: this will break when we start supporting smaller grain than DAY unless the time spine table is + # updated to use the smallest available grain. + if ( + time_dimension_spec.time_granularity.to_int() + < original_time_spine_dim_instance.spec.time_granularity.to_int() + ): + raise RuntimeError( + f"Can't join to time spine for a time dimension with a smaller granularity than that of the time " + f"spine column. Got {time_dimension_spec.time_granularity} for time dimension, " + f"{original_time_spine_dim_instance.spec.time_granularity} for time spine." + ) + + # Apply grain to time spine select expression, unless grain already matches original time spine column. select_expr: SqlExpressionNode = ( time_spine_column_select_expr - if time_dimension_spec.time_granularity == time_spine_dim_instance.spec.time_granularity + if time_dimension_spec.time_granularity == original_time_spine_dim_instance.spec.time_granularity else SqlDateTruncExpression( time_granularity=time_dimension_spec.time_granularity, arg=time_spine_column_select_expr ) @@ -1379,14 +1393,14 @@ def visit_join_to_time_spine_node(self, node: JoinToTimeSpineNode) -> SqlDataSet if time_dimension_spec.date_part: select_expr = SqlExtractExpression(date_part=time_dimension_spec.date_part, arg=select_expr) time_dim_spec = TimeDimensionSpec( - element_name=time_spine_dim_instance.spec.element_name, - entity_links=time_spine_dim_instance.spec.entity_links, + element_name=original_time_spine_dim_instance.spec.element_name, + entity_links=original_time_spine_dim_instance.spec.entity_links, time_granularity=time_dimension_spec.time_granularity, date_part=time_dimension_spec.date_part, - aggregation_state=time_spine_dim_instance.spec.aggregation_state, + aggregation_state=original_time_spine_dim_instance.spec.aggregation_state, ) time_spine_dim_instance = TimeDimensionInstance( - defined_from=time_spine_dim_instance.defined_from, + defined_from=original_time_spine_dim_instance.defined_from, associated_columns=(self._column_association_resolver.resolve_spec(time_dim_spec),), spec=time_dim_spec, ) diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index a366dbfa75..bdc24e7203 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -30,7 +30,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index c024f5be49..c4b1623e2c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -23,7 +23,7 @@ FROM ( subq_2.metric_time__month AS metric_time__month , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(year FROM subq_2.metric_time__month) AS metric_time__extract_year , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql index c7ab524c14..a9d3e6d977 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index d1d423597c..eb72ea9213 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql index a740353bfc..daf3021522 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql index aed26331bc..6f85a9e19f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index bd625c2bce..1d66e64171 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -356,7 +356,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 8fcd5b5b70..7871e327c5 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -357,7 +357,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 30e762031e..03120b4353 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -258,7 +258,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_8.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql index bd4671a650..8d51b413df 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_cumulative_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql index e60b7053b8..d04a641f27 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -31,7 +31,7 @@ FROM ( , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_2.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql index 6dd8959273..380c658a9e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index f34d48abce..aa0490fb4b 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -57,7 +57,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql index f75f60c01d..6c69cb987f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql index 06ad04b135..c0b1ea0b18 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_time_constraint__plan0.sql @@ -42,7 +42,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql index 342e0c87d5..a532fe0b30 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_offsets_with_where_constraint__plan0.sql @@ -46,7 +46,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 017e0f1383..c633e0a0db 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -37,7 +37,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql index cb53165033..8a62bf7c11 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -33,7 +33,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql index 5102273de1..8734e9a26a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index ee6af42a72..d3a6d4aadf 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -43,7 +43,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql index aabbfd61cc..92f1870c03 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_metric_multiple_granularities__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql index d4128818f7..10520fd03d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql index b17e12fe70..a3c227a694 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_time_offset_metric_with_time_constraint__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 62ea44b0ec..eb0612129b 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -260,7 +260,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql index 63fb598198..a0db6aa138 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_offset_window_with_date_part__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day From 89d2c2c91cc4014a7e592824e1a6a2fe874da6c4 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Thu, 29 Feb 2024 09:50:43 -0800 Subject: [PATCH 8/8] Update SQL engine snapshots --- ...ulative_time_offset_metric_with_time_constraint__plan0.sql | 2 +- ...d_metric_with_month_dimension_and_offset_window__plan0.sql | 2 +- .../test_derived_metric_with_offset_to_grain__plan0.sql | 2 +- ...ved_metric_with_offset_to_grain_and_granularity__plan0.sql | 2 +- .../test_derived_metric_with_offset_window__plan0.sql | 2 +- ...rived_metric_with_offset_window_and_granularity__plan0.sql | 2 +- ...d_metric_with_offset_window_and_offset_to_grain__plan0.sql | 4 ++-- ...fset_window_and_offset_to_grain_and_granularity__plan0.sql | 4 ++-- ...rived_metric_with_offset_window_and_time_filter__plan0.sql | 2 +- .../BigQuery/test_derived_offset_cumulative_metric__plan0.sql | 2 +- .../test_derived_offset_metric_with_agg_time_dim__plan0.sql | 2 +- ...est_derived_offset_metric_with_one_input_metric__plan0.sql | 2 +- ...ffset_with_joined_where_constraint_not_selected__plan0.sql | 2 +- .../SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql | 2 +- .../test_nested_offsets_with_time_constraint__plan0.sql | 2 +- .../test_nested_offsets_with_where_constraint__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...t_offset_to_grain_metric_multiple_granularities__plan0.sql | 2 +- .../test_offset_to_grain_with_agg_time_dim__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...est_offset_window_metric_multiple_granularities__plan0.sql | 2 +- .../BigQuery/test_offset_window_with_agg_time_dim__plan0.sql | 2 +- .../test_time_offset_metric_with_time_constraint__plan0.sql | 2 +- ...ulative_time_offset_metric_with_time_constraint__plan0.sql | 2 +- ...d_metric_with_month_dimension_and_offset_window__plan0.sql | 2 +- .../test_derived_metric_with_offset_to_grain__plan0.sql | 2 +- ...ved_metric_with_offset_to_grain_and_granularity__plan0.sql | 2 +- .../test_derived_metric_with_offset_window__plan0.sql | 2 +- ...rived_metric_with_offset_window_and_granularity__plan0.sql | 2 +- ...d_metric_with_offset_window_and_offset_to_grain__plan0.sql | 4 ++-- ...fset_window_and_offset_to_grain_and_granularity__plan0.sql | 4 ++-- ...rived_metric_with_offset_window_and_time_filter__plan0.sql | 2 +- .../test_derived_offset_cumulative_metric__plan0.sql | 2 +- .../test_derived_offset_metric_with_agg_time_dim__plan0.sql | 2 +- ...est_derived_offset_metric_with_one_input_metric__plan0.sql | 2 +- ...ffset_with_joined_where_constraint_not_selected__plan0.sql | 2 +- .../SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql | 2 +- .../test_nested_offsets_with_time_constraint__plan0.sql | 2 +- .../test_nested_offsets_with_where_constraint__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...t_offset_to_grain_metric_multiple_granularities__plan0.sql | 2 +- .../test_offset_to_grain_with_agg_time_dim__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...est_offset_window_metric_multiple_granularities__plan0.sql | 2 +- .../test_offset_window_with_agg_time_dim__plan0.sql | 2 +- .../test_time_offset_metric_with_time_constraint__plan0.sql | 2 +- ...ulative_time_offset_metric_with_time_constraint__plan0.sql | 2 +- ...d_metric_with_month_dimension_and_offset_window__plan0.sql | 2 +- .../test_derived_metric_with_offset_to_grain__plan0.sql | 2 +- ...ved_metric_with_offset_to_grain_and_granularity__plan0.sql | 2 +- .../test_derived_metric_with_offset_window__plan0.sql | 2 +- ...rived_metric_with_offset_window_and_granularity__plan0.sql | 2 +- ...d_metric_with_offset_window_and_offset_to_grain__plan0.sql | 4 ++-- ...fset_window_and_offset_to_grain_and_granularity__plan0.sql | 4 ++-- ...rived_metric_with_offset_window_and_time_filter__plan0.sql | 2 +- .../Postgres/test_derived_offset_cumulative_metric__plan0.sql | 2 +- .../test_derived_offset_metric_with_agg_time_dim__plan0.sql | 2 +- ...est_derived_offset_metric_with_one_input_metric__plan0.sql | 2 +- ...ffset_with_joined_where_constraint_not_selected__plan0.sql | 2 +- .../SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql | 2 +- .../test_nested_offsets_with_time_constraint__plan0.sql | 2 +- .../test_nested_offsets_with_where_constraint__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...t_offset_to_grain_metric_multiple_granularities__plan0.sql | 2 +- .../test_offset_to_grain_with_agg_time_dim__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...est_offset_window_metric_multiple_granularities__plan0.sql | 2 +- .../Postgres/test_offset_window_with_agg_time_dim__plan0.sql | 2 +- .../test_time_offset_metric_with_time_constraint__plan0.sql | 2 +- ...ulative_time_offset_metric_with_time_constraint__plan0.sql | 2 +- ...d_metric_with_month_dimension_and_offset_window__plan0.sql | 2 +- .../test_derived_metric_with_offset_to_grain__plan0.sql | 2 +- ...ved_metric_with_offset_to_grain_and_granularity__plan0.sql | 2 +- .../test_derived_metric_with_offset_window__plan0.sql | 2 +- ...rived_metric_with_offset_window_and_granularity__plan0.sql | 2 +- ...d_metric_with_offset_window_and_offset_to_grain__plan0.sql | 4 ++-- ...fset_window_and_offset_to_grain_and_granularity__plan0.sql | 4 ++-- ...rived_metric_with_offset_window_and_time_filter__plan0.sql | 2 +- .../Redshift/test_derived_offset_cumulative_metric__plan0.sql | 2 +- .../test_derived_offset_metric_with_agg_time_dim__plan0.sql | 2 +- ...est_derived_offset_metric_with_one_input_metric__plan0.sql | 2 +- ...ffset_with_joined_where_constraint_not_selected__plan0.sql | 2 +- .../SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql | 2 +- .../test_nested_offsets_with_time_constraint__plan0.sql | 2 +- .../test_nested_offsets_with_where_constraint__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...t_offset_to_grain_metric_multiple_granularities__plan0.sql | 2 +- .../test_offset_to_grain_with_agg_time_dim__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...est_offset_window_metric_multiple_granularities__plan0.sql | 2 +- .../Redshift/test_offset_window_with_agg_time_dim__plan0.sql | 2 +- .../test_time_offset_metric_with_time_constraint__plan0.sql | 2 +- ...ulative_time_offset_metric_with_time_constraint__plan0.sql | 2 +- ...d_metric_with_month_dimension_and_offset_window__plan0.sql | 2 +- .../test_derived_metric_with_offset_to_grain__plan0.sql | 2 +- ...ved_metric_with_offset_to_grain_and_granularity__plan0.sql | 2 +- .../test_derived_metric_with_offset_window__plan0.sql | 2 +- ...rived_metric_with_offset_window_and_granularity__plan0.sql | 2 +- ...d_metric_with_offset_window_and_offset_to_grain__plan0.sql | 4 ++-- ...fset_window_and_offset_to_grain_and_granularity__plan0.sql | 4 ++-- ...rived_metric_with_offset_window_and_time_filter__plan0.sql | 2 +- .../test_derived_offset_cumulative_metric__plan0.sql | 2 +- .../test_derived_offset_metric_with_agg_time_dim__plan0.sql | 2 +- ...est_derived_offset_metric_with_one_input_metric__plan0.sql | 2 +- ...ffset_with_joined_where_constraint_not_selected__plan0.sql | 2 +- .../SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql | 2 +- .../test_nested_offsets_with_time_constraint__plan0.sql | 2 +- .../test_nested_offsets_with_where_constraint__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...t_offset_to_grain_metric_multiple_granularities__plan0.sql | 2 +- .../test_offset_to_grain_with_agg_time_dim__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...est_offset_window_metric_multiple_granularities__plan0.sql | 2 +- .../Snowflake/test_offset_window_with_agg_time_dim__plan0.sql | 2 +- .../test_time_offset_metric_with_time_constraint__plan0.sql | 2 +- ...ulative_time_offset_metric_with_time_constraint__plan0.sql | 2 +- ...d_metric_with_month_dimension_and_offset_window__plan0.sql | 2 +- .../Trino/test_derived_metric_with_offset_to_grain__plan0.sql | 2 +- ...ved_metric_with_offset_to_grain_and_granularity__plan0.sql | 2 +- .../Trino/test_derived_metric_with_offset_window__plan0.sql | 2 +- ...rived_metric_with_offset_window_and_granularity__plan0.sql | 2 +- ...d_metric_with_offset_window_and_offset_to_grain__plan0.sql | 4 ++-- ...fset_window_and_offset_to_grain_and_granularity__plan0.sql | 4 ++-- ...rived_metric_with_offset_window_and_time_filter__plan0.sql | 2 +- .../Trino/test_derived_offset_cumulative_metric__plan0.sql | 2 +- .../test_derived_offset_metric_with_agg_time_dim__plan0.sql | 2 +- ...est_derived_offset_metric_with_one_input_metric__plan0.sql | 2 +- ...ffset_with_joined_where_constraint_not_selected__plan0.sql | 2 +- .../SqlQueryPlan/Trino/test_nested_offsets__plan0.sql | 2 +- .../Trino/test_nested_offsets_with_time_constraint__plan0.sql | 2 +- .../test_nested_offsets_with_where_constraint__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...t_offset_to_grain_metric_multiple_granularities__plan0.sql | 2 +- .../Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql | 2 +- ...c_filter_and_query_have_different_granularities__plan0.sql | 2 +- ...est_offset_window_metric_multiple_granularities__plan0.sql | 2 +- .../Trino/test_offset_window_with_agg_time_dim__plan0.sql | 2 +- .../test_time_offset_metric_with_time_constraint__plan0.sql | 2 +- .../test_derived_fill_nulls_for_one_input_metric__plan0.sql | 2 +- .../test_derived_fill_nulls_for_one_input_metric__plan0.sql | 2 +- .../test_derived_fill_nulls_for_one_input_metric__plan0.sql | 2 +- .../test_derived_fill_nulls_for_one_input_metric__plan0.sql | 2 +- .../test_derived_fill_nulls_for_one_input_metric__plan0.sql | 2 +- .../test_derived_fill_nulls_for_one_input_metric__plan0.sql | 2 +- .../BigQuery/test_offset_window_with_date_part__plan0.sql | 2 +- .../Databricks/test_offset_window_with_date_part__plan0.sql | 2 +- .../Postgres/test_offset_window_with_date_part__plan0.sql | 2 +- .../Redshift/test_offset_window_with_date_part__plan0.sql | 2 +- .../Snowflake/test_offset_window_with_date_part__plan0.sql | 2 +- .../Trino/test_offset_window_with_date_part__plan0.sql | 2 +- 150 files changed, 162 insertions(+), 162 deletions(-) diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index d2c5bfadcf..0bf3205339 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -30,7 +30,7 @@ FROM ( , DATE_TRUNC(subq_5.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_5.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_5.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_5.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 8fe6ff6836..696bb8b6fa 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -23,7 +23,7 @@ FROM ( subq_2.metric_time__month AS metric_time__month , DATE_TRUNC(subq_2.metric_time__month, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__month, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__month, month)) AS metric_time__extract_year + , EXTRACT(year FROM subq_2.metric_time__month) AS metric_time__extract_year , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql index 8bdb432802..a66e9f254c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC(subq_7.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_7.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_7.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_7.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 5e4c76815d..a22b40ecdf 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC(subq_7.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_7.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_7.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_7.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql index 8a428ddd21..86803dec46 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC(subq_7.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_7.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_7.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_7.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 72b321ab94..46ddd5cc8e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC(subq_7.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_7.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_7.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_7.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index f2e3424dd7..a2e78b069b 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -31,7 +31,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 @@ -356,7 +356,7 @@ FROM ( , DATE_TRUNC(subq_10.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_10.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_10.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_10.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index f667f7966a..8ddffc82cf 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -31,7 +31,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 @@ -357,7 +357,7 @@ FROM ( , DATE_TRUNC(subq_10.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_10.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_10.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_10.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index ee0e0e7396..e98d771f86 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -258,7 +258,7 @@ FROM ( , DATE_TRUNC(subq_8.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_8.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_8.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_8.metric_time__day, day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql index 2dc0542e6b..22c78e3564 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_cumulative_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , DATE_TRUNC(subq_5.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_5.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_5.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_5.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql index e629ec0111..17bd3518cd 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -31,7 +31,7 @@ FROM ( , DATE_TRUNC(subq_2.booking__ds__day, month) AS booking__ds__month , DATE_TRUNC(subq_2.booking__ds__day, quarter) AS booking__ds__quarter , DATE_TRUNC(subq_2.booking__ds__day, year) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.booking__ds__day, day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_2.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql index dea5b0b5b2..66f2a0fafe 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index df694e4e33..f021d4e62f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -57,7 +57,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql index 83512db0c0..5358d7845f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets__plan0.sql @@ -41,7 +41,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql index 15146a1d59..bbc68c9d92 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_time_constraint__plan0.sql @@ -42,7 +42,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql index 1de9e06484..ea13331f93 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_nested_offsets_with_where_constraint__plan0.sql @@ -46,7 +46,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index ef490bc65d..82b6ea15fc 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -37,7 +37,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql index fad7675aa8..9d7fedf6d3 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -33,7 +33,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql index b168018fc0..25d845a9c4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC(subq_7.booking__ds__day, month) AS booking__ds__month , DATE_TRUNC(subq_7.booking__ds__day, quarter) AS booking__ds__quarter , DATE_TRUNC(subq_7.booking__ds__day, year) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC(subq_7.booking__ds__day, day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index 61ddae66ea..a618d1766f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -43,7 +43,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql index 8dcf125ff4..2a96df9e68 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_metric_multiple_granularities__plan0.sql @@ -41,7 +41,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql index 463df5d0ce..477671fea5 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC(subq_7.booking__ds__day, month) AS booking__ds__month , DATE_TRUNC(subq_7.booking__ds__day, quarter) AS booking__ds__quarter , DATE_TRUNC(subq_7.booking__ds__day, year) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC(subq_7.booking__ds__day, day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql index 7d12e9fb15..300c2d0c9a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/BigQuery/test_time_offset_metric_with_time_constraint__plan0.sql @@ -25,7 +25,7 @@ FROM ( , DATE_TRUNC(subq_2.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_2.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_2.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_2.metric_time__day, day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 1b435f4495..649b310687 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -30,7 +30,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 2b3e35d6a0..cc8d1b968f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -23,7 +23,7 @@ FROM ( subq_2.metric_time__month AS metric_time__month , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(year FROM subq_2.metric_time__month) AS metric_time__extract_year , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql index 8ad6f65544..2e940367ea 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 348e92eae2..9dc762a3e9 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql index 02af4345b9..88329d00d3 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 1e89bbe0ed..0b40670060 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 536bc19f16..49d4478446 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -356,7 +356,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 009d8fd594..5f1bfa202f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -357,7 +357,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 2828f54a58..e7137cfe83 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -258,7 +258,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_8.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql index a614160904..8f195e3850 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_cumulative_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql index f49fdea2fa..97ea5f3d65 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -31,7 +31,7 @@ FROM ( , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_2.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql index c4ad2c66cb..52482d8b59 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index cc86591ea4..bbd320ac3b 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -57,7 +57,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql index ce28a61bf5..a692b115a4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql index 8c6d930be4..bf1783afa1 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_time_constraint__plan0.sql @@ -42,7 +42,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql index dc573f5598..bb78281744 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_nested_offsets_with_where_constraint__plan0.sql @@ -46,7 +46,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 9be1a0795e..4111729e97 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -37,7 +37,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql index 77d4118a1d..cf8bea400b 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -33,7 +33,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql index ecd2c408b3..0b46e69070 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index bef875a0de..04e5e6ec5e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -43,7 +43,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql index e882b9666d..a356026025 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_metric_multiple_granularities__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql index 000589c8d4..ea02464b08 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql index 92d9b8effa..a5f6c92502 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Databricks/test_time_offset_metric_with_time_constraint__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index b5849bfaef..7922d7265d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -30,7 +30,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 0787c597b5..b706aa2a9d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -23,7 +23,7 @@ FROM ( subq_2.metric_time__month AS metric_time__month , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(year FROM subq_2.metric_time__month) AS metric_time__extract_year , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql index c7ab524c14..a9d3e6d977 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index d1d423597c..eb72ea9213 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql index 60cf8b9286..c38796f09c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql index be4440178a..fbae91f2a9 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index c1a78af259..178cf2de2a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -356,7 +356,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 4366a9cac4..d50cfe18d9 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -357,7 +357,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index b264b7bc30..0fd450ec32 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -258,7 +258,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_8.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql index 672e3ef336..6d78aa9c64 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_cumulative_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql index e74ab5ef61..cc025f4b8c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -31,7 +31,7 @@ FROM ( , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_2.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql index 0733cbc2d4..bbb49e0a31 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 5a2dea6036..13cc66980b 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -57,7 +57,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql index 51cdf81e05..86b254f0a9 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql index 2270ea5b14..bdba4860e0 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_time_constraint__plan0.sql @@ -42,7 +42,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql index 36cd0d136a..777ebd13a2 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_nested_offsets_with_where_constraint__plan0.sql @@ -46,7 +46,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 017e0f1383..c633e0a0db 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -37,7 +37,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql index cb53165033..8a62bf7c11 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -33,7 +33,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql index 5102273de1..8734e9a26a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index a4d00f82aa..6c5dc6b093 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -43,7 +43,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql index b575040541..8a46329ece 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_metric_multiple_granularities__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql index cb19216291..a7b8e46f66 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql index 3444c0bc35..ca0633f023 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Postgres/test_time_offset_metric_with_time_constraint__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index dd82b1c685..946587cdba 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -30,7 +30,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 2b3e35d6a0..cc8d1b968f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -23,7 +23,7 @@ FROM ( subq_2.metric_time__month AS metric_time__month , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(year FROM subq_2.metric_time__month) AS metric_time__extract_year , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql index 4b4b364667..87688d112e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 7cb1f9cebc..be71703b1c 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql index 499afa7d23..a29a832f2d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql index 9536a26c3a..74fffe4c7f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index f1bb8e7757..581fd0e789 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -356,7 +356,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 733b6ea4ff..4ada8feb60 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -357,7 +357,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index bf8bf141c3..2838e435a1 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -258,7 +258,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_8.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql index 29881a2a31..7d11897fc7 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_cumulative_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 8cd0c3811d..ad6e88183b 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -31,7 +31,7 @@ FROM ( , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_2.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql index ccd62b038a..684a0f26a9 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index f8cf399747..77e4d19248 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -57,7 +57,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql index eb43b032d0..03f4118d5d 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql index 62277068b6..13ec96fc52 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_time_constraint__plan0.sql @@ -42,7 +42,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql index b804aa0a07..5be47d98a0 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_nested_offsets_with_where_constraint__plan0.sql @@ -46,7 +46,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index d92d99a040..9b7c4b2bef 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -37,7 +37,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql index 7dc8ce399a..cdd2a747bd 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -33,7 +33,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql index 3f9c5238ed..4b6fd05c9b 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index 6df1021844..796a8201a6 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -43,7 +43,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql index 0559050090..79cd48a29a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_metric_multiple_granularities__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql index d00776cddd..5a5d745cc6 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql index 898f838fe5..d847c8018f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Redshift/test_time_offset_metric_with_time_constraint__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index 3312de2574..306fc5aa5f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -30,7 +30,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 2b3e35d6a0..cc8d1b968f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -23,7 +23,7 @@ FROM ( subq_2.metric_time__month AS metric_time__month , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(year FROM subq_2.metric_time__month) AS metric_time__extract_year , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql index e66b477c12..5290ac6df3 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index b264cf74f6..a5aeefa790 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql index 203ba0d691..22ca211b78 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql index a72e8fe18b..0124c7102e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index d49e78644e..45404aae17 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -356,7 +356,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 9f73dd700c..d025b10978 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -357,7 +357,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index 071ed2411f..47ad965ef1 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -258,7 +258,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_8.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql index 912e9e864e..6945e41530 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_cumulative_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 4dade49a7c..9437092dd4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -31,7 +31,7 @@ FROM ( , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_2.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql index 969bf5c74c..3005816b74 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index fffb4a75b8..43aff53008 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -57,7 +57,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql index 4eedab48bd..116816a3e2 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql index ebb1e61bbd..c1169c26fb 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_time_constraint__plan0.sql @@ -42,7 +42,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql index 605ce6c166..9b11a266f0 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_nested_offsets_with_where_constraint__plan0.sql @@ -46,7 +46,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index b2ad329128..24810fdc57 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -37,7 +37,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql index 6928c03ba1..9ba2ba9c0a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -33,7 +33,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql index 8a86991b51..179b098943 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index 17b50cf308..09bf3b33db 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -43,7 +43,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql index 0f47dd4f42..041daf1029 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_metric_multiple_granularities__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql index ee5e543017..896d161dff 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql index 2002794d0a..a1a6c46c56 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Snowflake/test_time_offset_metric_with_time_constraint__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql index eb0a49b46d..ff9b7c69df 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql @@ -30,7 +30,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql index 3f17f3a766..ab37f732b5 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql @@ -23,7 +23,7 @@ FROM ( subq_2.metric_time__month AS metric_time__month , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('month', subq_2.metric_time__month)) AS metric_time__extract_year + , EXTRACT(year FROM subq_2.metric_time__month) AS metric_time__extract_year , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month , subq_1.monthly_ds__month AS monthly_ds__month diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql index 3e6dc1b7db..2e3eaf8475 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql index 966d7ff296..25b6c37530 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql index d43892ad7f..219b53a81e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql index d2e0aedb53..7a7f0cef1f 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql index 15f6e068b1..ff70de61e8 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -356,7 +356,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql index 7933040c75..9f5f5a9b1e 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0.sql @@ -31,7 +31,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 @@ -357,7 +357,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql index f016a9b7db..6cbd2d5ff1 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql @@ -258,7 +258,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_8.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql index 7b87d6d566..5e647c5106 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_5.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql index 9f2cdb9266..fe961785b5 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_agg_time_dim__plan0.sql @@ -31,7 +31,7 @@ FROM ( , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_2.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_2.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql index c54fdc5fdc..385bcc0ba0 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql index 12d140dba7..080be3077a 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql @@ -57,7 +57,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql index fa7a593c6d..44af827d27 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql index ab68677f9c..7f06fe45be 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql @@ -42,7 +42,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql index ae0aa7c66d..6245df2b52 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql @@ -46,7 +46,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql index 16bd80f75b..26bb799b98 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_filter_and_query_have_different_granularities__plan0.sql @@ -37,7 +37,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql index 811e12ab3e..3491cd1852 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_metric_multiple_granularities__plan0.sql @@ -33,7 +33,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql index df25d92345..29c0d4d062 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_to_grain_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql index 6fdfb94137..119f12fed2 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_filter_and_query_have_different_granularities__plan0.sql @@ -43,7 +43,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql index 3fd4cf1276..1dc6e47519 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_metric_multiple_granularities__plan0.sql @@ -41,7 +41,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql index 9e3c1baff4..acfa5e5aeb 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_agg_time_dim__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.booking__ds__day)) AS booking__ds__extract_year + , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql index 18b04ecaf4..a58a3aa8d4 100644 --- a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql +++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql @@ -25,7 +25,7 @@ FROM ( , 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 DATE_TRUNC('day', subq_2.metric_time__day)) AS metric_time__extract_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 diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 902a797b7d..b217d55a19 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/BigQuery/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -260,7 +260,7 @@ FROM ( , DATE_TRUNC(subq_10.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_10.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_10.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_10.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 5ee0f4feb8..1f30074712 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Databricks/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -260,7 +260,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 1f0c027154..eab935741e 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Postgres/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -260,7 +260,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql index cb63347d0c..560ae7e845 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Redshift/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -260,7 +260,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 1c065b2f6c..333d2eaaba 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Snowflake/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -260,7 +260,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql index 25062782ab..1c645ecec6 100644 --- a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql +++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql @@ -260,7 +260,7 @@ FROM ( , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_10.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql index 6b4b711158..93ca1a32ec 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/BigQuery/test_offset_window_with_date_part__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC(subq_7.metric_time__day, month) AS metric_time__month , DATE_TRUNC(subq_7.metric_time__day, quarter) AS metric_time__quarter , DATE_TRUNC(subq_7.metric_time__day, year) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC(subq_7.metric_time__day, day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql index 686d0bb018..2320e8b134 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Databricks/test_offset_window_with_date_part__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql index c2f5365be1..7229cf2062 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Postgres/test_offset_window_with_date_part__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql index 61503885d9..a6a4c2d5f9 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Redshift/test_offset_window_with_date_part__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql index fb53d48b83..9ebe5b940a 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Snowflake/test_offset_window_with_date_part__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql index 6c7471d513..eacfae4235 100644 --- a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql +++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql @@ -246,7 +246,7 @@ FROM ( , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM DATE_TRUNC('day', subq_7.metric_time__day)) AS metric_time__extract_year + , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day