diff --git a/.changes/unreleased/Features-20231008-195608.yaml b/.changes/unreleased/Features-20231008-195608.yaml
new file mode 100644
index 0000000000..bd16ae0233
--- /dev/null
+++ b/.changes/unreleased/Features-20231008-195608.yaml
@@ -0,0 +1,6 @@
+kind: Features
+body: Add Trino support to the MetricFlow.
+time: 2023-10-08T19:56:08.427006-06:00
+custom:
+ Author: sarbmeetka
+ Issue: "207"
diff --git a/.github/workflows/cd-sql-engine-tests.yaml b/.github/workflows/cd-sql-engine-tests.yaml
index 41923d54b9..c509cea11e 100644
--- a/.github/workflows/cd-sql-engine-tests.yaml
+++ b/.github/workflows/cd-sql-engine-tests.yaml
@@ -91,6 +91,29 @@ jobs:
additional-pytest-options: ${{ env.ADDITIONAL_PYTEST_OPTIONS }}
make-target: "test-databricks"
+ trino-tests:
+ # Trino tests run on a local service container, which obviates the need for separate Environment hosting.
+ # We run them here instead of in the CI unit test suite because they are a bit slower, and because in future
+ # we may choose to execute them against a hosted instance, at which point this config will look like the other
+ # engine configs in this file.
+ name: Trino Tests
+ if: ${{ github.event.action != 'labeled' || github.event.label.name == 'Run Tests With Other SQL Engines' }}
+ runs-on: ubuntu-latest
+ services:
+ trino:
+ image: trinodb/trino
+ ports:
+ - 8080:8080
+ steps:
+ - name: Check-out the repo
+ uses: actions/checkout@v3
+
+ - name: Test w/ Python 3.11
+ uses: ./.github/actions/run-mf-tests
+ with:
+ python-version: "3.11"
+ make-target: "test-trino"
+
remove-label:
name: Remove Label After Running Tests
runs-on: ubuntu-latest
diff --git a/Makefile b/Makefile
index 41eb3d1d16..92dfc2a12a 100644
--- a/Makefile
+++ b/Makefile
@@ -59,6 +59,9 @@ test-snowflake:
populate-persistent-source-schema-snowflake:
hatch -v run snowflake-env:pytest -vv $(ADDITIONAL_PYTEST_OPTIONS) $(USE_PERSISTENT_SOURCE_SCHEMA) $(POPULATE_PERSISTENT_SOURCE_SCHEMA)
+.PHONY: test-trino
+test-trino:
+ hatch -v run trino-env:pytest -vv -n $(PARALLELISM) $(ADDITIONAL_PYTEST_OPTIONS) metricflow/test/
.PHONY: lint
lint:
diff --git a/dbt-metricflow/pyproject.toml b/dbt-metricflow/pyproject.toml
index 99ac4043d4..5715f2b79f 100644
--- a/dbt-metricflow/pyproject.toml
+++ b/dbt-metricflow/pyproject.toml
@@ -50,6 +50,9 @@ redshift = [
snowflake = [
"dbt-snowflake~=1.7.0"
]
+trino = [
+ "dbt-trino~=1.7.0"
+]
[tool.hatch.build.targets.sdist]
exclude = [
diff --git a/metricflow/cli/dbt_connectors/adapter_backed_client.py b/metricflow/cli/dbt_connectors/adapter_backed_client.py
index 09180aabca..cc15d521a9 100644
--- a/metricflow/cli/dbt_connectors/adapter_backed_client.py
+++ b/metricflow/cli/dbt_connectors/adapter_backed_client.py
@@ -21,6 +21,7 @@
from metricflow.sql.render.redshift import RedshiftSqlQueryPlanRenderer
from metricflow.sql.render.snowflake import SnowflakeSqlQueryPlanRenderer
from metricflow.sql.render.sql_plan_renderer import SqlQueryPlanRenderer
+from metricflow.sql.render.trino import TrinoSqlQueryPlanRenderer
from metricflow.sql.sql_bind_parameters import SqlBindParameters
from metricflow.sql_request.sql_request_attributes import SqlJsonTag, SqlRequestId, SqlRequestTagSet
from metricflow.sql_request.sql_statement_metadata import CombinedSqlTags, SqlStatementCommentMetadata
@@ -42,6 +43,7 @@ class SupportedAdapterTypes(enum.Enum):
REDSHIFT = "redshift"
BIGQUERY = "bigquery"
DUCKDB = "duckdb"
+ TRINO = "trino"
@property
def sql_engine_type(self) -> SqlEngine:
@@ -58,6 +60,8 @@ def sql_engine_type(self) -> SqlEngine:
return SqlEngine.SNOWFLAKE
elif self is SupportedAdapterTypes.DUCKDB:
return SqlEngine.DUCKDB
+ elif self is SupportedAdapterTypes.TRINO:
+ return SqlEngine.TRINO
else:
assert_values_exhausted(self)
@@ -76,6 +80,8 @@ def sql_query_plan_renderer(self) -> SqlQueryPlanRenderer:
return SnowflakeSqlQueryPlanRenderer()
elif self is SupportedAdapterTypes.DUCKDB:
return DuckDbSqlQueryPlanRenderer()
+ elif self is SupportedAdapterTypes.TRINO:
+ return TrinoSqlQueryPlanRenderer()
else:
assert_values_exhausted(self)
@@ -213,7 +219,18 @@ def dry_run(
request_id = SqlRequestId(f"mf_rid__{random_id()}")
connection_name = f"MetricFlow_dry_run_request_{request_id}"
# TODO - consolidate to self._adapter.validate_sql() when all implementations will work from within MetricFlow
- if self.sql_engine_type is SqlEngine.BIGQUERY:
+
+ # Trino has a bug where explain command actually creates table. Wrapping with validate to avoid this.
+ # See https://github.com/trinodb/trino/issues/130
+ if self.sql_engine_type is SqlEngine.TRINO:
+ with self._adapter.connection_named(connection_name):
+ # Either the response will be bool value or a string with error message from Trino.
+ result = self._adapter.execute(f"EXPLAIN (type validate) {stmt}", auto_begin=True, fetch=True)
+ has_error = False if str(result[0]) == "SUCCESS" else True
+ if has_error:
+ raise DbtDatabaseError("Encountered error in Trino dry run.")
+
+ elif self.sql_engine_type is SqlEngine.BIGQUERY:
with self._adapter.connection_named(connection_name):
self._adapter.validate_sql(stmt)
else:
diff --git a/metricflow/protocols/sql_client.py b/metricflow/protocols/sql_client.py
index 8497002559..b9e9588ac4 100644
--- a/metricflow/protocols/sql_client.py
+++ b/metricflow/protocols/sql_client.py
@@ -23,6 +23,7 @@ class SqlEngine(Enum):
POSTGRES = "Postgres"
SNOWFLAKE = "Snowflake"
DATABRICKS = "Databricks"
+ TRINO = "Trino"
class SqlClient(Protocol):
diff --git a/metricflow/sql/render/trino.py b/metricflow/sql/render/trino.py
new file mode 100644
index 0000000000..b767240f21
--- /dev/null
+++ b/metricflow/sql/render/trino.py
@@ -0,0 +1,126 @@
+from __future__ import annotations
+
+from typing import Collection
+
+from dateutil.parser import parse
+from dbt_semantic_interfaces.enum_extension import assert_values_exhausted
+from dbt_semantic_interfaces.type_enums.date_part import DatePart
+from dbt_semantic_interfaces.type_enums.time_granularity import TimeGranularity
+from typing_extensions import override
+
+from metricflow.sql.render.expr_renderer import (
+ DefaultSqlExpressionRenderer,
+ SqlExpressionRenderer,
+ SqlExpressionRenderResult,
+)
+from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer
+from metricflow.sql.sql_bind_parameters import SqlBindParameters
+from metricflow.sql.sql_exprs import (
+ SqlBetweenExpression,
+ SqlGenerateUuidExpression,
+ SqlPercentileExpression,
+ SqlPercentileFunctionType,
+ SqlSubtractTimeIntervalExpression,
+)
+
+
+class TrinoSqlExpressionRenderer(DefaultSqlExpressionRenderer):
+ """Expression renderer for the Trino engine."""
+
+ @property
+ @override
+ def supported_percentile_function_types(self) -> Collection[SqlPercentileFunctionType]:
+ return {
+ SqlPercentileFunctionType.APPROXIMATE_CONTINUOUS,
+ }
+
+ @override
+ def visit_generate_uuid_expr(self, node: SqlGenerateUuidExpression) -> SqlExpressionRenderResult:
+ return SqlExpressionRenderResult(
+ sql="uuid()",
+ bind_parameters=SqlBindParameters(),
+ )
+
+ @override
+ def visit_time_delta_expr(self, node: SqlSubtractTimeIntervalExpression) -> SqlExpressionRenderResult:
+ """Render time delta for Trino, require granularity in quotes and function name change."""
+ arg_rendered = node.arg.accept(self)
+
+ count = node.count
+ granularity = node.granularity
+ if granularity == TimeGranularity.QUARTER:
+ granularity = TimeGranularity.MONTH
+ count *= 3
+ return SqlExpressionRenderResult(
+ sql=f"DATE_ADD('{granularity.value}', -{count}, {arg_rendered.sql})",
+ bind_parameters=arg_rendered.bind_parameters,
+ )
+
+ @override
+ def visit_percentile_expr(self, node: SqlPercentileExpression) -> SqlExpressionRenderResult:
+ """Render a percentile expression for Trino."""
+ arg_rendered = self.render_sql_expr(node.order_by_arg)
+ params = arg_rendered.bind_parameters
+ percentile = node.percentile_args.percentile
+
+ if node.percentile_args.function_type is SqlPercentileFunctionType.APPROXIMATE_CONTINUOUS:
+ return SqlExpressionRenderResult(
+ sql=f"approx_percentile({arg_rendered.sql}, {percentile})",
+ bind_parameters=params,
+ )
+ elif (
+ node.percentile_args.function_type is SqlPercentileFunctionType.APPROXIMATE_DISCRETE
+ or node.percentile_args.function_type is SqlPercentileFunctionType.DISCRETE
+ or node.percentile_args.function_type is SqlPercentileFunctionType.CONTINUOUS
+ ):
+ raise RuntimeError(
+ "Discrete, Continuous and Approximate discrete percentile aggregates are not supported for Trino. Set "
+ + "use_approximate_percentile and disable use_discrete_percentile in all percentile measures."
+ )
+ else:
+ assert_values_exhausted(node.percentile_args.function_type)
+
+ @override
+ def visit_between_expr(self, node: SqlBetweenExpression) -> SqlExpressionRenderResult:
+ """Render a between expression for Trino. If the expression is a timestamp literal then wrap literals with timestamp."""
+ rendered_column_arg = self.render_sql_expr(node.column_arg)
+ rendered_start_expr = self.render_sql_expr(node.start_expr)
+ rendered_end_expr = self.render_sql_expr(node.end_expr)
+
+ bind_parameters = SqlBindParameters()
+ bind_parameters = bind_parameters.combine(rendered_column_arg.bind_parameters)
+ bind_parameters = bind_parameters.combine(rendered_start_expr.bind_parameters)
+ bind_parameters = bind_parameters.combine(rendered_end_expr.bind_parameters)
+
+ # Handle timestamp literals differently.
+ if parse(rendered_start_expr.sql):
+ sql = f"{rendered_column_arg.sql} BETWEEN timestamp {rendered_start_expr.sql} AND timestamp {rendered_end_expr.sql}"
+ else:
+ sql = f"{rendered_column_arg.sql} BETWEEN {rendered_start_expr.sql} AND {rendered_end_expr.sql}"
+
+ return SqlExpressionRenderResult(
+ sql=sql,
+ bind_parameters=bind_parameters,
+ )
+
+ @override
+ def render_date_part(self, date_part: DatePart) -> str:
+ """Render DATE PART for an EXTRACT expression.
+
+ Override DAY_OF_WEEK in Trino to ISO date part to ensure all engines return consistent results.
+ """
+ if date_part is DatePart.DOW:
+ return "DAY_OF_WEEK"
+
+ return date_part.value
+
+
+class TrinoSqlQueryPlanRenderer(DefaultSqlQueryPlanRenderer):
+ """Plan renderer for the Trino engine."""
+
+ EXPR_RENDERER = TrinoSqlExpressionRenderer()
+
+ @property
+ @override
+ def expr_renderer(self) -> SqlExpressionRenderer:
+ return self.EXPR_RENDERER
diff --git a/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml b/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml
index 3285cb836b..99316d5df8 100644
--- a/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml
+++ b/metricflow/test/fixtures/dbt_projects/metricflow_testing/profiles.yml
@@ -67,3 +67,14 @@ duckdb:
dev:
type: duckdb
schema: "{{ env_var('DBT_ENV_SECRET_SCHEMA') }}"
+trino:
+ target: dev
+ outputs:
+ dev:
+ type: trino
+ host: "{{ env_var('DBT_ENV_SECRET_HOST') }}"
+ port: "{{ env_var('DBT_PROFILE_PORT') | int }}"
+ user: "{{ env_var('DBT_ENV_SECRET_USER') }}"
+ password: "{{ env_var('DBT_ENV_SECRET_PASSWORD') }}"
+ catalog: "{{ env_var('DBT_ENV_SECRET_CATALOG') }}"
+ schema: "{{ env_var('DBT_ENV_SECRET_SCHEMA') }}"
diff --git a/metricflow/test/fixtures/sql_client_fixtures.py b/metricflow/test/fixtures/sql_client_fixtures.py
index b54e019f4d..7ab950bf9e 100644
--- a/metricflow/test/fixtures/sql_client_fixtures.py
+++ b/metricflow/test/fixtures/sql_client_fixtures.py
@@ -42,6 +42,9 @@
DBT_ENV_SECRET_PROJECT_ID = "DBT_ENV_SECRET_PROJECT_ID"
DBT_ENV_SECRET_TOKEN_URI = "DBT_ENV_SECRET_TOKEN_URI"
+# Trino is special, so it gets its own set of env vars. Keeping them split out here for consistency.
+DBT_ENV_SECRET_CATALOG = "DBT_ENV_SECRET_CATALOG"
+
def __configure_test_env_from_url(url: str, password: str, schema: str) -> sqlalchemy.engine.URL:
"""Populates default env var mapping from a sqlalchemy URL string.
@@ -163,6 +166,10 @@ def make_test_sql_client(url: str, password: str, schema: str) -> SqlClientWithD
__configure_databricks_env_from_url(url, password=password, schema=schema)
__initialize_dbt()
return AdapterBackedDDLSqlClient(adapter=get_adapter_by_type("databricks"))
+ elif dialect == SqlDialect.TRINO:
+ __configure_test_env_from_url(url, password=password, schema=schema)
+ __initialize_dbt()
+ return AdapterBackedDDLSqlClient(adapter=get_adapter_by_type("trino"))
else:
raise ValueError(f"Unknown dialect: `{dialect}` in URL {url}")
diff --git a/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py b/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py
index 33e603bbc1..b0e99535fb 100644
--- a/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py
+++ b/metricflow/test/fixtures/sql_clients/adapter_backed_ddl_client.py
@@ -39,6 +39,7 @@ def create_table_from_dataframe(
# This mirrors the SQLAlchemy schema detection logic in pandas.io.sql
df = df.convert_dtypes()
columns = df.columns
+
columns_to_insert = []
for i in range(len(df.columns)):
# Format as "column_name column_type"
@@ -63,7 +64,12 @@ def create_table_from_dataframe(
elif type(cell) in [str, pd.Timestamp]:
# Wrap cell in quotes & escape existing single quotes
escaped_cell = self._quote_escape_value(str(cell))
- cells.append(f"'{escaped_cell}'")
+ # Trino requires timestamp literals to be wrapped in a timestamp() function.
+ # There is probably a better way to handle this.
+ if self.sql_engine_type is SqlEngine.TRINO and type(cell) is pd.Timestamp:
+ cells.append(f"timestamp '{escaped_cell}'")
+ else:
+ cells.append(f"'{escaped_cell}'")
else:
cells.append(str(cell))
@@ -93,6 +99,8 @@ def _get_type_from_pandas_dtype(self, dtype: str) -> str:
if dtype == "string" or dtype == "object":
if self.sql_engine_type is SqlEngine.DATABRICKS or self.sql_engine_type is SqlEngine.BIGQUERY:
return "string"
+ if self.sql_engine_type is SqlEngine.TRINO:
+ return "varchar"
return "text"
elif dtype == "boolean" or dtype == "bool":
return "boolean"
diff --git a/metricflow/test/fixtures/sql_clients/common_client.py b/metricflow/test/fixtures/sql_clients/common_client.py
index 4273d0d12e..ddda32aea8 100644
--- a/metricflow/test/fixtures/sql_clients/common_client.py
+++ b/metricflow/test/fixtures/sql_clients/common_client.py
@@ -14,6 +14,7 @@ class SqlDialect(ExtendedEnum):
SNOWFLAKE = "snowflake"
BIGQUERY = "bigquery"
DATABRICKS = "databricks"
+ TRINO = "trino"
T = TypeVar("T")
diff --git a/metricflow/test/generate_snapshots.py b/metricflow/test/generate_snapshots.py
index 3be91cb750..38eb97d3d7 100644
--- a/metricflow/test/generate_snapshots.py
+++ b/metricflow/test/generate_snapshots.py
@@ -28,6 +28,10 @@
"engine_url": postgres://...",
"engine_password": "..."
},
+ "trino": {
+ "engine_url": trino://...",
+ "engine_password": "..."
+ },
}
EOF
)
@@ -69,6 +73,7 @@ class MetricFlowTestCredentialSetForAllEngines(FrozenBaseModel): # noqa: D
big_query: MetricFlowTestCredentialSet
databricks: MetricFlowTestCredentialSet
postgres: MetricFlowTestCredentialSet
+ trino: MetricFlowTestCredentialSet
@property
def as_configurations(self) -> Sequence[MetricFlowTestConfiguration]: # noqa: D
@@ -97,6 +102,10 @@ def as_configurations(self) -> Sequence[MetricFlowTestConfiguration]: # noqa: D
engine=SqlEngine.POSTGRES,
credential_set=self.postgres,
),
+ MetricFlowTestConfiguration(
+ engine=SqlEngine.TRINO,
+ credential_set=self.trino,
+ ),
)
@@ -137,6 +146,7 @@ def run_tests(test_configuration: MetricFlowTestConfiguration) -> None: # noqa:
or test_configuration.engine is SqlEngine.BIGQUERY
or test_configuration.engine is SqlEngine.DATABRICKS
or test_configuration.engine is SqlEngine.POSTGRES
+ or test_configuration.engine is SqlEngine.TRINO
):
engine_name = test_configuration.engine.value.lower()
os.environ["MF_TEST_ADAPTER_TYPE"] = engine_name
diff --git a/metricflow/test/integration/query_output/test_cumulative_metrics.py b/metricflow/test/integration/query_output/test_cumulative_metrics.py
index 026c840dd1..eeff2bf9a1 100644
--- a/metricflow/test/integration/query_output/test_cumulative_metrics.py
+++ b/metricflow/test/integration/query_output/test_cumulative_metrics.py
@@ -133,15 +133,18 @@ def test_cumulative_metric_with_non_adjustable_filter(
it_helpers: IntegrationTestHelpers,
) -> None:
"""Tests a cumulative metric with a filter that cannot be adjusted to ensure all data is included."""
+ # Handle ds expression based on engine to support Trino.
+ first_ds_expr = f"CAST('2020-03-15' AS {sql_client.sql_query_plan_renderer.expr_renderer.timestamp_data_type})"
+ second_ds_expr = f"CAST('2020-04-30' AS {sql_client.sql_query_plan_renderer.expr_renderer.timestamp_data_type})"
+ where_constraint = f"{{{{ TimeDimension('metric_time', 'day') }}}} = {first_ds_expr} or"
+ where_constraint += f" {{{{ TimeDimension('metric_time', 'day') }}}} = {second_ds_expr}"
+
query_result = it_helpers.mf_engine.query(
MetricFlowQueryRequest.create_with_random_request_id(
metric_names=["trailing_2_months_revenue"],
group_by_names=["metric_time"],
order_by_names=["metric_time"],
- where_constraint=(
- "{{ TimeDimension('metric_time', 'day') }} = '2020-03-15' or "
- "{{ TimeDimension('metric_time', 'day') }} = '2020-04-30'"
- ),
+ where_constraint=where_constraint,
time_constraint_end=as_datetime("2020-12-31"),
)
)
diff --git a/metricflow/test/integration/test_cases/itest_constraints.yaml b/metricflow/test/integration/test_cases/itest_constraints.yaml
index 925c4e8db6..7022d736ab 100644
--- a/metricflow/test/integration/test_cases/itest_constraints.yaml
+++ b/metricflow/test/integration/test_cases/itest_constraints.yaml
@@ -56,7 +56,7 @@ integration_test:
SELECT SUM(booking_value) AS booking_value
, ds AS metric_time__day
FROM {{ source_schema }}.fct_bookings b
- WHERE ds = '2020-01-01'
+ WHERE {{ render_time_constraint("ds", "2020-01-01", "2020-01-01") }}
GROUP BY
ds
---
@@ -73,7 +73,7 @@ integration_test:
, ds AS metric_time__day
FROM {{ source_schema }}.fct_bookings b
WHERE is_instant
- and ds = '2020-01-01'
+ and {{ render_time_constraint("ds", "2020-01-01", "2020-01-01") }}
GROUP BY ds
---
integration_test:
@@ -142,11 +142,11 @@ integration_test:
model: SIMPLE_MODEL
metrics: ["bookings"]
group_bys: ["metric_time"]
- where_filter: "{{ render_time_dimension_template('metric_time') }} = '2020-01-01'"
+ where_filter: "{{ render_time_dimension_template('metric_time') }} = {{ cast_to_ts('2020-01-01') }}"
check_query: |
SELECT
SUM(1) AS bookings
, ds AS metric_time__day
FROM {{ source_schema }}.fct_bookings
- WHERE ds = '2020-01-01'
+ WHERE ds = {{ cast_to_ts('2020-01-01') }}
GROUP BY ds
diff --git a/metricflow/test/integration/test_cases/itest_cumulative_metric.yaml b/metricflow/test/integration/test_cases/itest_cumulative_metric.yaml
index 67b4315b2b..a86a9ea838 100644
--- a/metricflow/test/integration/test_cases/itest_cumulative_metric.yaml
+++ b/metricflow/test/integration/test_cases/itest_cumulative_metric.yaml
@@ -325,8 +325,8 @@ integration_test:
group_bys: ["metric_time__day"]
order_bys: ["metric_time__day"]
where_filter: |
- {{ render_time_dimension_template('metric_time', 'day') }} = '2019-12-20'
- or {{ render_time_dimension_template('metric_time', 'day') }} = '2020-01-04'
+ {{ render_time_dimension_template('metric_time', 'day') }} = {{ cast_to_ts('2019-12-20') }}
+ or {{ render_time_dimension_template('metric_time', 'day') }} = {{ cast_to_ts('2020-01-04') }}
check_query: |
SELECT
COUNT (DISTINCT(b.guest_id)) as every_two_days_bookers
diff --git a/metricflow/test/integration/test_cases/itest_granularity.yaml b/metricflow/test/integration/test_cases/itest_granularity.yaml
index 7aee578af1..ea3f974516 100644
--- a/metricflow/test/integration/test_cases/itest_granularity.yaml
+++ b/metricflow/test/integration/test_cases/itest_granularity.yaml
@@ -25,7 +25,7 @@ integration_test:
, {{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week
FROM {{ source_schema }}.fct_bookings_extended
GROUP BY
- metric_time__week
+ {{ render_date_trunc("ds", TimeGranularity.WEEK) }}
---
integration_test:
name: query_granularity_for_sum_month
@@ -39,7 +39,7 @@ integration_test:
, {{ render_date_trunc("ds", TimeGranularity.MONTH) }} AS metric_time__month
FROM {{ source_schema }}.fct_bookings_extended
GROUP BY
- metric_time__month
+ {{ render_date_trunc("ds", TimeGranularity.MONTH) }}
---
integration_test:
name: query_granularity_for_sum_quarter
@@ -53,7 +53,7 @@ integration_test:
, {{ render_date_trunc("ds", TimeGranularity.QUARTER) }} AS metric_time__quarter
FROM {{ source_schema }}.fct_bookings_extended
GROUP BY
- metric_time__quarter
+ {{ render_date_trunc("ds", TimeGranularity.QUARTER) }}
---
integration_test:
name: query_granularity_for_sum_year
@@ -67,7 +67,7 @@ integration_test:
, {{ render_date_trunc("ds", TimeGranularity.YEAR) }} AS metric_time__year
FROM {{ source_schema }}.fct_bookings_extended
GROUP BY
- metric_time__year
+ {{ render_date_trunc("ds", TimeGranularity.YEAR) }}
---
integration_test:
name: query_granularity_for_count_distinct_day
@@ -95,7 +95,7 @@ integration_test:
, {{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week
FROM {{ source_schema }}.fct_bookings_extended
GROUP BY
- metric_time__week
+ {{ render_date_trunc("ds", TimeGranularity.WEEK) }}
---
integration_test:
name: query_granularity_for_count_distinct_month
@@ -109,7 +109,7 @@ integration_test:
, {{ render_date_trunc("ds", TimeGranularity.MONTH) }} AS metric_time__month
FROM {{ source_schema }}.fct_bookings_extended
GROUP BY
- metric_time__month
+ {{ render_date_trunc("ds", TimeGranularity.MONTH) }}
---
integration_test:
name: query_granularity_for_count_distinct_quarter
@@ -123,7 +123,7 @@ integration_test:
, {{ render_date_trunc("ds", TimeGranularity.QUARTER) }} AS metric_time__quarter
FROM {{ source_schema }}.fct_bookings_extended
GROUP BY
- metric_time__quarter
+ {{ render_date_trunc("ds", TimeGranularity.QUARTER) }}
---
integration_test:
name: query_granularity_for_count_distinct_year
@@ -137,7 +137,7 @@ integration_test:
, {{ render_date_trunc("ds", TimeGranularity.YEAR) }} AS metric_time__year
FROM {{ source_schema }}.fct_bookings_extended
GROUP BY
- metric_time__year
+ {{ render_date_trunc("ds", TimeGranularity.YEAR) }}
---
integration_test:
name: query_granularity_for_joined_dundered_dimension_day
@@ -185,7 +185,7 @@ integration_test:
FROM {{ source_schema }}.fct_bookings_extended_monthly
WHERE {{ render_time_constraint("ds", "2020-01-01", "2020-02-29") }}
GROUP BY
- metric_time__month
+ ds
---
integration_test:
name: metric_with_non_day_granularity_on_non_boundaries
@@ -201,7 +201,7 @@ integration_test:
FROM {{ source_schema }}.fct_bookings_extended_monthly
WHERE {{ render_time_constraint("ds", "2020-01-01", "2020-02-29") }}
GROUP BY
- metric_time__month
+ ds
---
integration_test:
name: weekly_metric_on_non_boundaries
@@ -217,7 +217,7 @@ integration_test:
FROM {{ source_schema }}.fct_bookings_extended
WHERE {{ render_time_constraint("ds", "2020-01-13", "2020-01-26") }}
GROUP BY
- metric_time__week
+ {{ render_date_trunc("ds", TimeGranularity.WEEK) }}
---
integration_test:
name: daily_metric_with_monthly_time_dimension
@@ -233,7 +233,7 @@ integration_test:
FROM {{ source_schema }}.fct_bookings_extended
WHERE {{ render_time_constraint("ds", "2020-01-01", "2020-01-31") }}
GROUP BY
- metric_time__month
+ {{ render_date_trunc("ds", TimeGranularity.MONTH) }}
---
integration_test:
name: metrics_with_different_time_granularities
@@ -273,7 +273,7 @@ integration_test:
ON a.ds = b.ds
) c
GROUP BY
- metric_time__month
+ ds
---
integration_test:
name: metrics_with_different_time_granularities_and_no_metric_time
diff --git a/metricflow/test/integration/test_cases/itest_metrics.yaml b/metricflow/test/integration/test_cases/itest_metrics.yaml
index 2625e9b0c7..26ae81116f 100644
--- a/metricflow/test/integration/test_cases/itest_metrics.yaml
+++ b/metricflow/test/integration/test_cases/itest_metrics.yaml
@@ -489,7 +489,7 @@ integration_test:
group_bys: ["metric_time"]
check_query: |
SELECT
- (bookings - ref_bookings) / CAST(bookings AS {{ double_data_type_name }}) AS non_referred_bookings_pct
+ (bookings - ref_bookings) * 1.0 / bookings AS non_referred_bookings_pct
, metric_time__day
FROM (
SELECT
@@ -688,7 +688,7 @@ integration_test:
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings
GROUP BY
- metric_time__day
+ ds
) a
FULL OUTER JOIN (
SELECT
@@ -701,7 +701,7 @@ integration_test:
, SUM(1) AS bookings_2_weeks_ago
FROM {{ source_schema }}.fct_bookings
GROUP BY
- metric_time__day
+ ds
) d
ON {{ render_date_sub("C", "ds", 14, TimeGranularity.DAY) }} = d.metric_time__day
) b
@@ -723,7 +723,7 @@ integration_test:
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings
GROUP BY
- metric_time__day
+ ds
) a
FULL OUTER JOIN (
SELECT
@@ -736,7 +736,7 @@ integration_test:
, SUM(1) AS bookings_at_start_of_month
FROM {{ source_schema }}.fct_bookings
GROUP BY
- metric_time__day
+ ds
) d
ON {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = d.metric_time__day
) b
@@ -763,7 +763,7 @@ integration_test:
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings
GROUP BY
- metric_time__day
+ ds
) f
ON {{ render_date_sub("g", "ds", 1, TimeGranularity.MONTH) }} = f.metric_time__day
) a
@@ -778,7 +778,7 @@ integration_test:
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings
GROUP BY
- metric_time__day
+ ds
) d
ON {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = d.metric_time__day
) b
@@ -801,7 +801,7 @@ integration_test:
, SUM(1) AS bookings_5_day_lag
FROM {{ source_schema }}.fct_bookings
GROUP BY
- metric_time__day
+ ds
) b
ON {{ render_date_sub("a", "ds", 5, TimeGranularity.DAY) }} = b.metric_time__day
---
@@ -889,7 +889,7 @@ integration_test:
FROM {{ source_schema }}.fct_bookings
) b
ON {{ render_date_sub("a", "ds", 5, TimeGranularity.DAY) }} = b.metric_time__day
- GROUP BY metric_time__month
+ GROUP BY {{ render_date_trunc("a.ds", TimeGranularity.MONTH) }}
---
integration_test:
name: derived_metric_with_offset_to_grain_and_granularity
@@ -906,7 +906,7 @@ integration_test:
{{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings
- GROUP BY metric_time__week
+ GROUP BY {{ render_date_trunc("ds", TimeGranularity.WEEK) }}
) a
FULL OUTER JOIN (
SELECT
@@ -921,7 +921,7 @@ integration_test:
) d
ON {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = d.metric_time__day
WHERE {{ render_date_trunc("c.ds", TimeGranularity.WEEK) }} = c.ds
- GROUP BY metric_time__week
+ GROUP BY {{ render_date_trunc("c.ds", TimeGranularity.WEEK) }}
) b
ON a.metric_time__week = b.metric_time__week
---
@@ -949,7 +949,7 @@ integration_test:
FROM {{ source_schema }}.fct_bookings
) f
ON {{ render_date_sub("g", "ds", 1, TimeGranularity.MONTH) }} = f.metric_time__day
- GROUP BY metric_time__year
+ GROUP BY {{ render_date_trunc("g.ds", TimeGranularity.YEAR) }}
) a
FULL OUTER JOIN (
SELECT
@@ -964,7 +964,7 @@ integration_test:
) d
ON {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = d.metric_time__day
WHERE {{ render_date_trunc("c.ds", TimeGranularity.YEAR) }} = c.ds
- GROUP BY metric_time__year
+ GROUP BY {{ render_date_trunc("c.ds", TimeGranularity.YEAR) }}
) b
ON a.metric_time__year = b.metric_time__year
---
@@ -987,7 +987,7 @@ integration_test:
FROM {{ mf_time_spine_source }} a
INNER JOIN {{ source_schema }}.fct_bookings b
ON (b.ds <= a.ds) AND (b.ds > {{ render_date_sub("a", "ds", 2, TimeGranularity.DAY) }})
- GROUP BY metric_time__day
+ GROUP BY a.ds
) c
ON {{ render_date_sub("d", "ds", 2, TimeGranularity.DAY) }} = c.metric_time__day
---
@@ -1010,7 +1010,7 @@ integration_test:
FROM {{ source_schema }}.fct_bookings
) b
ON {{ render_date_sub("a", "ds", 5, TimeGranularity.DAY) }} = b.metric_time__day
- GROUP BY metric_time__month, metric_time__week
+ GROUP BY {{ render_date_trunc("a.ds", TimeGranularity.MONTH) }}, {{ render_date_trunc("a.ds", TimeGranularity.WEEK) }}
---
integration_test:
name: derived_metric_with_offset_to_grain_and_multiple_granularities
@@ -1029,7 +1029,7 @@ integration_test:
, {{ render_date_trunc("ds", TimeGranularity.MONTH) }} AS metric_time__month
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings
- GROUP BY metric_time__week, metric_time__month
+ GROUP BY {{ render_date_trunc("ds", TimeGranularity.WEEK) }}, {{ render_date_trunc("ds", TimeGranularity.MONTH) }}
) a
FULL OUTER JOIN (
SELECT
@@ -1046,7 +1046,7 @@ integration_test:
ON {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = d.metric_time__day
WHERE {{ render_date_trunc("c.ds", TimeGranularity.WEEK) }} = c.ds
OR {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }} = c.ds
- GROUP BY metric_time__week, metric_time__month
+ GROUP BY {{ render_date_trunc("c.ds", TimeGranularity.WEEK) }}, {{ render_date_trunc("c.ds", TimeGranularity.MONTH) }}
) b
ON a.metric_time__week = b.metric_time__week
AND a.metric_time__month = b.metric_time__month
@@ -1120,7 +1120,7 @@ integration_test:
FROM {{ source_schema }}.fct_bookings
) b
ON {{ render_date_sub("a", "ds", 5, TimeGranularity.DAY) }} = b.metric_time__day
- GROUP BY metric_time__extract_month
+ GROUP BY {{ render_extract("a.ds", DatePart.MONTH) }}
---
integration_test:
name: simple_distinct_query_with_date_part
@@ -1151,7 +1151,7 @@ integration_test:
{{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings bookings_source_src_1
- GROUP BY metric_time__day
+ GROUP BY 1
) subq_3
ON subq_5.ds = subq_3.metric_time__day
---
@@ -1169,14 +1169,14 @@ integration_test:
SELECT
{{ render_date_trunc("ds", TimeGranularity.MONTH) }} AS metric_time__month
FROM {{ source_schema }}.mf_time_spine subq_5
- GROUP BY metric_time__month
+ GROUP BY 1
) subq_4
LEFT OUTER JOIN (
SELECT
{{ render_date_trunc("ds", TimeGranularity.MONTH) }} AS metric_time__month
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings bookings_source_src_1
- GROUP BY metric_time__month
+ GROUP BY 1
) subq_3
ON subq_4.metric_time__month = subq_3.metric_time__month
---
@@ -1192,7 +1192,7 @@ integration_test:
, COALESCE(SUM(1), 0) AS bookings_fill_nulls_with_0
FROM {{ source_schema }}.fct_bookings bookings_source_src_1
GROUP BY
- booking__paid_at__day
+ 1
---
integration_test:
name: simple_fill_nulls_with_0_with_categorical_dimension
@@ -1205,7 +1205,7 @@ integration_test:
is_instant AS booking__is_instant
, COALESCE(SUM(1), 0) AS bookings_fill_nulls_with_0
FROM {{ source_schema }}.fct_bookings bookings_source_src_1
- GROUP BY booking__is_instant
+ GROUP BY 1
---
integration_test:
name: simple_join_to_time_spine
@@ -1224,7 +1224,7 @@ integration_test:
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings bookings_source_src_1
GROUP BY
- metric_time__day
+ 1
) subq_3
ON
subq_5.ds = subq_3.metric_time__day
@@ -1240,7 +1240,7 @@ integration_test:
{{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day
, COALESCE(SUM(1), 0) AS bookings_fill_nulls_with_0_without_time_spine
FROM {{ source_schema }}.fct_bookings bookings_source_src_1
- GROUP BY metric_time__day
+ GROUP BY 1
---
integration_test:
name: cumulative_fill_nulls
@@ -1293,7 +1293,7 @@ integration_test:
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings bookings_source_src_1
GROUP BY
- metric_time__day
+ 1
) subq_3
ON subq_5.ds = subq_3.metric_time__day
) subq_7
@@ -1336,7 +1336,7 @@ integration_test:
{{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings bookings_source_src_1
- GROUP BY metric_time__day
+ GROUP BY 1
) subq_3
ON subq_5.ds = subq_3.metric_time__day
) subq_7
@@ -1345,7 +1345,7 @@ integration_test:
{{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day
, SUM(1) AS views
FROM {{ source_schema }}.fct_views views_source_src_9
- GROUP BY metric_time__day
+ GROUP BY 1
) subq_12
ON subq_7.metric_time__day = subq_12.metric_time__day
GROUP BY COALESCE(subq_7.metric_time__day, subq_12.metric_time__day)
@@ -1384,7 +1384,7 @@ integration_test:
{{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day
, SUM(1) AS bookings
FROM {{ source_schema }}.fct_bookings bookings_source_src_1
- GROUP BY metric_time__day
+ GROUP BY 1
) subq_3
ON subq_5.ds = subq_3.metric_time__day
) subq_6
@@ -1679,7 +1679,7 @@ integration_test:
SELECT
ds AS metric_time__day
FROM {{ source_schema }}.mf_time_spine subq_6
- WHERE ds BETWEEN '2019-12-19' AND '2020-01-02'
+ WHERE {{ render_between_time_constraint("ds", "2019-12-19", "2020-01-02") }}
) subq_5
INNER JOIN (
SELECT
diff --git a/metricflow/test/integration/test_cases/itest_order_limit.yaml b/metricflow/test/integration/test_cases/itest_order_limit.yaml
index b8a1f6b44d..0cc563056a 100644
--- a/metricflow/test/integration/test_cases/itest_order_limit.yaml
+++ b/metricflow/test/integration/test_cases/itest_order_limit.yaml
@@ -69,6 +69,6 @@ integration_test:
, SUM(booking_value) AS booking_value
FROM {{ source_schema }}.fct_bookings
GROUP BY
- metric_time__month
+ 1
ORDER BY
metric_time__month DESC, booking_value
diff --git a/metricflow/test/integration/test_cases/itest_scd.yaml b/metricflow/test/integration/test_cases/itest_scd.yaml
index 42e3d5a980..b44b444060 100644
--- a/metricflow/test/integration/test_cases/itest_scd.yaml
+++ b/metricflow/test/integration/test_cases/itest_scd.yaml
@@ -15,7 +15,7 @@ integration_test:
ON a.listing_id = b.listing_id
AND a.ds >= b.active_from AND (a.ds < b.active_to OR b.active_to is NULL)
GROUP BY
- listing__capacity, metric_time__day
+ capacity, ds
---
integration_test:
name: basic_scd_constrained_metric
@@ -35,7 +35,7 @@ integration_test:
WHERE b.capacity >= 3
GROUP BY
is_instant
- , metric_time__day
+ , ds
---
integration_test:
name: scd_constrained_metric_with_nulls
@@ -61,8 +61,8 @@ integration_test:
WHERE b.is_lux OR b.is_lux IS NULL
GROUP BY
is_instant
- , metric_time__day
- , listing__is_lux
+ , ds
+ , is_lux
---
integration_test:
name: scd_grouped_metric_with_second_dim
@@ -87,9 +87,9 @@ integration_test:
LEFT OUTER JOIN {{ source_schema }}.dim_users_latest c
ON b.user_id = c.user_id
GROUP BY
- metric_time__day
- , listing__is_lux
- , listing__user__home_state_latest
+ a.ds
+ , b.is_lux
+ , c.home_state_latest
---
integration_test:
name: scd_multi_hop_groupby_through_scd
@@ -112,8 +112,8 @@ integration_test:
LEFT OUTER JOIN {{ source_schema }}.dim_users_latest c
ON b.user_id = c.user_id
GROUP BY
- metric_time__day
- , listing__user__home_state_latest
+ a.ds
+ , c.home_state_latest
---
integration_test:
name: scd_multi_hop_groupby_to_scd
@@ -136,5 +136,5 @@ integration_test:
ON b.lux_listing_id = c.lux_listing_id
AND a.ds >= c.valid_from AND (a.ds < c.valid_to OR c.valid_to is NULL)
GROUP BY
- metric_time__day
- , listing__lux_listing__is_confirmed_lux
+ a.ds
+ , c.is_confirmed_lux
diff --git a/metricflow/test/integration/test_cases/itest_semi_additive_measure.yaml b/metricflow/test/integration/test_cases/itest_semi_additive_measure.yaml
index 9043723f43..59cb7429f3 100644
--- a/metricflow/test/integration/test_cases/itest_semi_additive_measure.yaml
+++ b/metricflow/test/integration/test_cases/itest_semi_additive_measure.yaml
@@ -55,7 +55,7 @@ integration_test:
, MAX(ds) AS ds
FROM {{ source_schema }}.fct_accounts
GROUP BY
- metric_time__week
+ {{ render_date_trunc("ds", TimeGranularity.WEEK) }}
, user_id
) b
ON
@@ -85,7 +85,7 @@ integration_test:
, {{ render_date_trunc("ds", TimeGranularity.DAY) }} AS metric_time__day
FROM {{ source_schema }}.fct_accounts
GROUP BY
- metric_time__day
+ {{ render_date_trunc("ds", TimeGranularity.DAY) }}
) b
ON
a.ds = b.ds
@@ -167,7 +167,7 @@ integration_test:
, {{ render_date_trunc("ds", TimeGranularity.WEEK) }} AS metric_time__week
FROM {{ source_schema }}.fct_accounts
GROUP BY
- metric_time__week
+ {{ render_date_trunc("ds", TimeGranularity.WEEK) }}
) b
ON
a.ds = b.ds
@@ -226,7 +226,7 @@ integration_test:
model: SIMPLE_MODEL
metrics: ["total_account_balance_first_day"]
group_bys: ["account__account_type"]
- where_filter: "{{ render_time_dimension_template('account__ds', 'day') }} >= '2020-01-03'"
+ where_filter: "{{ render_time_dimension_template('account__ds', 'day') }} >= {{ cast_to_ts('2020-01-03') }}"
check_query: |
SELECT
b.account_type AS account__account_type
@@ -243,7 +243,7 @@ integration_test:
, account_balance AS total_account_balance_first_day
FROM {{ source_schema }}.fct_accounts
) a
- WHERE ds >= '2020-01-03'
+ WHERE ds >= {{ cast_to_ts('2020-01-03') }}
) b
INNER JOIN (
SELECT
@@ -253,7 +253,7 @@ integration_test:
ds
FROM {{ source_schema }}.fct_accounts
) c
- WHERE ds >= '2020-01-03'
+ WHERE ds >= {{ cast_to_ts('2020-01-03') }}
) d
ON
b.ds = d.ds__complete
diff --git a/metricflow/test/integration/test_cases/itest_simple.yaml b/metricflow/test/integration/test_cases/itest_simple.yaml
index e4dc5cb5d6..96dd48a71b 100644
--- a/metricflow/test/integration/test_cases/itest_simple.yaml
+++ b/metricflow/test/integration/test_cases/itest_simple.yaml
@@ -42,7 +42,7 @@ integration_test:
SUM(booking_value) AS booking_value
, ds AS metric_time__day
FROM {{ source_schema }}.fct_bookings
- WHERE {{ render_time_constraint("ds", "2020-01-01", "2020-01-01") }}
+ WHERE {{ render_between_time_constraint("ds", "2020-01-01", "2020-01-01") }}
GROUP BY
ds
---
diff --git a/metricflow/test/integration/test_cases/itest_simple_non_sm.yaml b/metricflow/test/integration/test_cases/itest_simple_non_sm.yaml
index 8096844835..5f17dccd5e 100644
--- a/metricflow/test/integration/test_cases/itest_simple_non_sm.yaml
+++ b/metricflow/test/integration/test_cases/itest_simple_non_sm.yaml
@@ -15,7 +15,7 @@ integration_test:
FROM {{ source_schema }}.fct_bookings_dt b
LEFT OUTER JOIN {{ source_schema }}.dim_listings_latest l
ON b.listing_id = l.listing_id
- WHERE {{ render_time_constraint("dt", "2020-01-01", "2020-01-01") }}
+ WHERE {{ render_between_time_constraint("dt", "2020-01-01", "2020-01-01") }}
GROUP BY
b.is_instant
, b.dt
diff --git a/metricflow/test/integration/test_configured_cases.py b/metricflow/test/integration/test_configured_cases.py
index b8a8420df2..dcf6722d8b 100644
--- a/metricflow/test/integration/test_configured_cases.py
+++ b/metricflow/test/integration/test_configured_cases.py
@@ -67,8 +67,25 @@ def render_time_constraint(
stop_time_plus_one_day = (
datetime.datetime.strptime(stop_time, time_format) + datetime.timedelta(days=1)
).strftime(time_format)
+
stop_expr = self.cast_to_ts(f"{stop_time_plus_one_day}")
- return f"{expr} >= {start_expr} AND {expr} < {stop_expr}"
+ return f"{self.cast_expr_to_ts(expr)} >= {start_expr} AND {self.cast_expr_to_ts(expr)} < {stop_expr}"
+
+ def render_between_time_constraint(
+ self,
+ expr: str,
+ start_time: str,
+ stop_time: str,
+ ) -> str:
+ """Render an expression like "ds between timestamp '2020-01-01' AND timestamp '2020-01-02'".
+
+ This will cast the literals as needed for each engine, and provide an alternative to incrementing
+ the date as we do in render_time_constraint. Using BETWEEN is more robust for cases involving potentially
+ mixed granularities.
+ """
+ start_expr = self.cast_to_ts(f"{start_time}")
+ stop_expr = self.cast_to_ts(f"{stop_time}")
+ return f"{expr} BETWEEN {start_expr} AND {stop_expr}"
def cast_expr_to_ts(self, expr: str) -> str:
"""Returns the expression as a new expression cast to the timestamp type, if applicable for the DB."""
@@ -290,6 +307,7 @@ def test_case(
).render(
source_schema=mf_test_session_state.mf_source_schema,
render_time_constraint=check_query_helpers.render_time_constraint,
+ render_between_time_constraint=check_query_helpers.render_between_time_constraint,
TimeGranularity=TimeGranularity,
DatePart=DatePart,
render_date_sub=check_query_helpers.render_date_sub,
@@ -302,6 +320,7 @@ def test_case(
render_entity_template=check_query_helpers.render_entity_template,
render_time_dimension_template=check_query_helpers.render_time_dimension_template,
generate_random_uuid=check_query_helpers.generate_random_uuid,
+ cast_to_ts=check_query_helpers.cast_to_ts,
)
if case.where_filter
else None,
@@ -318,6 +337,7 @@ def test_case(
).render(
source_schema=mf_test_session_state.mf_source_schema,
render_time_constraint=check_query_helpers.render_time_constraint,
+ render_between_time_constraint=check_query_helpers.render_between_time_constraint,
TimeGranularity=TimeGranularity,
DatePart=DatePart,
render_date_sub=check_query_helpers.render_date_sub,
@@ -327,6 +347,7 @@ def test_case(
mf_time_spine_source=semantic_manifest_lookup.time_spine_source.spine_table.sql,
double_data_type_name=check_query_helpers.double_data_type_name,
generate_random_uuid=check_query_helpers.generate_random_uuid,
+ cast_to_ts=check_query_helpers.cast_to_ts,
)
)
# If we sort, it's effectively not checking the order whatever order that the output was would be overwritten.
diff --git a/metricflow/test/populate_persistent_source_schemas.py b/metricflow/test/populate_persistent_source_schemas.py
index 0f0ff6f59c..a37412216b 100644
--- a/metricflow/test/populate_persistent_source_schemas.py
+++ b/metricflow/test/populate_persistent_source_schemas.py
@@ -29,6 +29,7 @@ def populate_schemas(test_configuration: MetricFlowTestConfiguration) -> None:
or test_configuration.engine is SqlEngine.BIGQUERY
or test_configuration.engine is SqlEngine.DATABRICKS
or test_configuration.engine is SqlEngine.REDSHIFT
+ or test_configuration.engine is SqlEngine.TRINO
):
engine_name = test_configuration.engine.value.lower()
os.environ["MF_TEST_ADAPTER_TYPE"] = engine_name
diff --git a/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query__cli_output.txt
new file mode 100644
index 0000000000..138d8b140e
--- /dev/null
+++ b/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query__cli_output.txt
@@ -0,0 +1,11 @@
+| metric_time__day | listing__capacity_latest | bookings | instant_bookings |
+|:--------------------|---------------------------:|-----------:|-------------------:|
+| 2019-12-01 00:00:00 | 5 | 1 | 0 |
+| 2019-12-18 00:00:00 | 4 | 4 | 2 |
+| 2019-12-19 00:00:00 | 4 | 6 | 6 |
+| 2019-12-19 00:00:00 | 5 | 2 | 0 |
+| 2019-12-20 00:00:00 | 5 | 2 | 0 |
+| 2020-01-01 00:00:00 | 4 | 2 | 1 |
+| 2020-01-02 00:00:00 | 4 | 3 | 3 |
+| 2020-01-02 00:00:00 | 5 | 1 | 0 |
+| 2020-01-03 00:00:00 | 5 | 1 | 0 |
diff --git a/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query_with_cumulative_metric__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query_with_cumulative_metric__cli_output.txt
new file mode 100644
index 0000000000..7e7a1fea49
--- /dev/null
+++ b/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query_with_cumulative_metric__cli_output.txt
@@ -0,0 +1,3 @@
+| metric_time__day | trailing_2_months_revenue |
+|:--------------------|----------------------------:|
+| 2020-01-01 00:00:00 | 1000 |
diff --git a/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query_with_limit__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query_with_limit__cli_output.txt
new file mode 100644
index 0000000000..313b03eda8
--- /dev/null
+++ b/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query_with_limit__cli_output.txt
@@ -0,0 +1,5 @@
+| metric_time__day | listing__capacity_latest | bookings | instant_bookings |
+|:--------------------|---------------------------:|-----------:|-------------------:|
+| 2019-12-01 00:00:00 | 5 | 1 | 0 |
+| 2019-12-18 00:00:00 | 4 | 4 | 2 |
+| 2019-12-19 00:00:00 | 4 | 6 | 6 |
diff --git a/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query_with_where__cli_output.txt b/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query_with_where__cli_output.txt
new file mode 100644
index 0000000000..fc66131bbc
--- /dev/null
+++ b/metricflow/test/snapshots/test_cli.py/str/Trino/test_saved_query_with_where__cli_output.txt
@@ -0,0 +1,7 @@
+| metric_time__day | listing__capacity_latest | bookings | instant_bookings |
+|:--------------------|---------------------------:|-----------:|-------------------:|
+| 2019-12-01 00:00:00 | 5 | 1 | 0 |
+| 2019-12-19 00:00:00 | 5 | 2 | 0 |
+| 2019-12-20 00:00:00 | 5 | 2 | 0 |
+| 2020-01-02 00:00:00 | 5 | 1 | 0 |
+| 2020-01-03 00:00:00 | 5 | 1 | 0 |
diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0.sql
new file mode 100644
index 0000000000..4c0412c4e4
--- /dev/null
+++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0.sql
@@ -0,0 +1,346 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_14.buys AS visit_buy_conversions
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ MAX(subq_3.visits) AS visits
+ , COALESCE(MAX(subq_13.buys), 0) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_2.visits) AS visits
+ FROM (
+ -- Pass Only Elements:
+ -- ['visits']
+ SELECT
+ subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_10011.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy
+ , visits_source_src_10011.referrer_id
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy
+ , visits_source_src_10011.referrer_id AS visit__referrer_id
+ , visits_source_src_10011.user_id AS user
+ , visits_source_src_10011.session_id AS session
+ , visits_source_src_10011.user_id AS visit__user
+ , visits_source_src_10011.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ ) subq_3
+ CROSS JOIN (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_12.buys) AS buys
+ FROM (
+ -- Pass Only Elements:
+ -- ['buys']
+ SELECT
+ subq_11.buys
+ FROM (
+ -- Find conversions for user within the range of 7 day
+ SELECT
+ subq_10.ds__day
+ , subq_10.user
+ , subq_10.buys
+ , subq_10.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ first_value(subq_6.visits) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits
+ , first_value(subq_6.ds__day) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day
+ , first_value(subq_6.user) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS user
+ , subq_9.mf_internal_uuid AS mf_internal_uuid
+ , subq_9.buys AS buys
+ FROM (
+ -- Pass Only Elements:
+ -- ['visits', 'ds__day', 'user']
+ SELECT
+ subq_5.ds__day
+ , subq_5.user
+ , subq_5.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_4.ds__day
+ , subq_4.ds__week
+ , subq_4.ds__month
+ , subq_4.ds__quarter
+ , subq_4.ds__year
+ , subq_4.ds__extract_year
+ , subq_4.ds__extract_quarter
+ , subq_4.ds__extract_month
+ , subq_4.ds__extract_day
+ , subq_4.ds__extract_dow
+ , subq_4.ds__extract_doy
+ , subq_4.visit__ds__day
+ , subq_4.visit__ds__week
+ , subq_4.visit__ds__month
+ , subq_4.visit__ds__quarter
+ , subq_4.visit__ds__year
+ , subq_4.visit__ds__extract_year
+ , subq_4.visit__ds__extract_quarter
+ , subq_4.visit__ds__extract_month
+ , subq_4.visit__ds__extract_day
+ , subq_4.visit__ds__extract_dow
+ , subq_4.visit__ds__extract_doy
+ , subq_4.ds__day AS metric_time__day
+ , subq_4.ds__week AS metric_time__week
+ , subq_4.ds__month AS metric_time__month
+ , subq_4.ds__quarter AS metric_time__quarter
+ , subq_4.ds__year AS metric_time__year
+ , subq_4.ds__extract_year AS metric_time__extract_year
+ , subq_4.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_4.ds__extract_month AS metric_time__extract_month
+ , subq_4.ds__extract_day AS metric_time__extract_day
+ , subq_4.ds__extract_dow AS metric_time__extract_dow
+ , subq_4.ds__extract_doy AS metric_time__extract_doy
+ , subq_4.user
+ , subq_4.session
+ , subq_4.visit__user
+ , subq_4.visit__session
+ , subq_4.referrer_id
+ , subq_4.visit__referrer_id
+ , subq_4.visits
+ , subq_4.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_10011.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy
+ , visits_source_src_10011.referrer_id
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy
+ , visits_source_src_10011.referrer_id AS visit__referrer_id
+ , visits_source_src_10011.user_id AS user
+ , visits_source_src_10011.session_id AS session
+ , visits_source_src_10011.user_id AS visit__user
+ , visits_source_src_10011.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_4
+ ) subq_5
+ ) subq_6
+ INNER JOIN (
+ -- Add column with generated UUID
+ 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.buy__ds__day
+ , subq_8.buy__ds__week
+ , subq_8.buy__ds__month
+ , subq_8.buy__ds__quarter
+ , subq_8.buy__ds__year
+ , subq_8.buy__ds__extract_year
+ , subq_8.buy__ds__extract_quarter
+ , subq_8.buy__ds__extract_month
+ , subq_8.buy__ds__extract_day
+ , subq_8.buy__ds__extract_dow
+ , subq_8.buy__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session_id
+ , subq_8.buy__user
+ , subq_8.buy__session_id
+ , subq_8.buys
+ , subq_8.buyers
+ , uuid() AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.buy__ds__day
+ , subq_7.buy__ds__week
+ , subq_7.buy__ds__month
+ , subq_7.buy__ds__quarter
+ , subq_7.buy__ds__year
+ , subq_7.buy__ds__extract_year
+ , subq_7.buy__ds__extract_quarter
+ , subq_7.buy__ds__extract_month
+ , subq_7.buy__ds__extract_day
+ , subq_7.buy__ds__extract_dow
+ , subq_7.buy__ds__extract_doy
+ , subq_7.ds__day AS metric_time__day
+ , subq_7.ds__week AS metric_time__week
+ , subq_7.ds__month AS metric_time__month
+ , subq_7.ds__quarter AS metric_time__quarter
+ , subq_7.ds__year AS metric_time__year
+ , subq_7.ds__extract_year AS metric_time__extract_year
+ , subq_7.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_7.ds__extract_month AS metric_time__extract_month
+ , subq_7.ds__extract_day AS metric_time__extract_day
+ , subq_7.ds__extract_dow AS metric_time__extract_dow
+ , subq_7.ds__extract_doy AS metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session_id
+ , subq_7.buy__user
+ , subq_7.buy__session_id
+ , subq_7.buys
+ , subq_7.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_10002.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_10002.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_10002.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_10002.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_10002.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_10002.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_10002.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_10002.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_10002.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_10002.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_10002.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_10002.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_10002.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_10002.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_10002.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_10002.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_10002.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_10002.ds) AS buy__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_10002.ds) AS buy__ds__extract_doy
+ , buys_source_src_10002.user_id AS user
+ , buys_source_src_10002.session_id
+ , buys_source_src_10002.user_id AS buy__user
+ , buys_source_src_10002.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_10002
+ ) subq_7
+ ) subq_8
+ ) subq_9
+ ON
+ (
+ subq_6.user = subq_9.user
+ ) AND (
+ (
+ subq_6.ds__day <= subq_9.ds__day
+ ) AND (
+ subq_6.ds__day > DATE_ADD('day', -7, subq_9.ds__day)
+ )
+ )
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ ) subq_13
+) subq_14
diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0_optimized.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0_optimized.sql
new file mode 100644
index 0000000000..0f90cf24a3
--- /dev/null
+++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_count_with_no_group_by__plan0_optimized.sql
@@ -0,0 +1,63 @@
+-- Combine Aggregated Outputs
+-- Compute Metrics via Expressions
+SELECT
+ COALESCE(MAX(subq_28.buys), 0) AS visit_buy_conversions
+FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['visits']
+ -- Aggregate Measures
+ SELECT
+ SUM(1) AS visits
+ FROM ***************************.fct_visits visits_source_src_10011
+) subq_18
+CROSS JOIN (
+ -- Find conversions for user within the range of 7 day
+ -- Pass Only Elements:
+ -- ['buys']
+ -- Aggregate Measures
+ SELECT
+ SUM(buys) AS buys
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ first_value(subq_21.visits) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits
+ , first_value(subq_21.ds__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day
+ , first_value(subq_21.user) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS user
+ , subq_24.mf_internal_uuid AS mf_internal_uuid
+ , subq_24.buys AS buys
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['visits', 'ds__day', 'user']
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_21
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
+ -- Add column with generated UUID
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , 1 AS buys
+ , uuid() AS mf_internal_uuid
+ FROM ***************************.fct_buys buys_source_src_10002
+ ) subq_24
+ ON
+ (
+ subq_21.user = subq_24.user
+ ) AND (
+ (
+ subq_21.ds__day <= subq_24.ds__day
+ ) AND (
+ subq_21.ds__day > DATE_ADD('day', -7, subq_24.ds__day)
+ )
+ )
+ ) subq_25
+) subq_28
diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0.sql
new file mode 100644
index 0000000000..b4aba824fb
--- /dev/null
+++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0.sql
@@ -0,0 +1,355 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_14.visit__referrer_id
+ , CAST(subq_14.buys AS DOUBLE) / CAST(NULLIF(subq_14.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_3.visits) AS visits
+ , MAX(subq_13.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.visit__referrer_id
+ , SUM(subq_2.visits) AS visits
+ FROM (
+ -- Pass Only Elements:
+ -- ['visits', 'visit__referrer_id']
+ SELECT
+ subq_1.visit__referrer_id
+ , subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_10011.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy
+ , visits_source_src_10011.referrer_id
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy
+ , visits_source_src_10011.referrer_id AS visit__referrer_id
+ , visits_source_src_10011.user_id AS user
+ , visits_source_src_10011.session_id AS session
+ , visits_source_src_10011.user_id AS visit__user
+ , visits_source_src_10011.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.visit__referrer_id
+ ) subq_3
+ FULL OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ subq_12.visit__referrer_id
+ , SUM(subq_12.buys) AS buys
+ FROM (
+ -- Pass Only Elements:
+ -- ['buys', 'visit__referrer_id']
+ SELECT
+ subq_11.visit__referrer_id
+ , subq_11.buys
+ FROM (
+ -- Find conversions for user within the range of INF
+ SELECT
+ subq_10.ds__day
+ , subq_10.user
+ , subq_10.visit__referrer_id
+ , subq_10.buys
+ , subq_10.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ first_value(subq_6.visits) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits
+ , first_value(subq_6.visit__referrer_id) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visit__referrer_id
+ , first_value(subq_6.ds__day) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day
+ , first_value(subq_6.user) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS user
+ , subq_9.mf_internal_uuid AS mf_internal_uuid
+ , subq_9.buys AS buys
+ FROM (
+ -- Pass Only Elements:
+ -- ['visits', 'visit__referrer_id', 'ds__day', 'user']
+ SELECT
+ subq_5.ds__day
+ , subq_5.user
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_4.ds__day
+ , subq_4.ds__week
+ , subq_4.ds__month
+ , subq_4.ds__quarter
+ , subq_4.ds__year
+ , subq_4.ds__extract_year
+ , subq_4.ds__extract_quarter
+ , subq_4.ds__extract_month
+ , subq_4.ds__extract_day
+ , subq_4.ds__extract_dow
+ , subq_4.ds__extract_doy
+ , subq_4.visit__ds__day
+ , subq_4.visit__ds__week
+ , subq_4.visit__ds__month
+ , subq_4.visit__ds__quarter
+ , subq_4.visit__ds__year
+ , subq_4.visit__ds__extract_year
+ , subq_4.visit__ds__extract_quarter
+ , subq_4.visit__ds__extract_month
+ , subq_4.visit__ds__extract_day
+ , subq_4.visit__ds__extract_dow
+ , subq_4.visit__ds__extract_doy
+ , subq_4.ds__day AS metric_time__day
+ , subq_4.ds__week AS metric_time__week
+ , subq_4.ds__month AS metric_time__month
+ , subq_4.ds__quarter AS metric_time__quarter
+ , subq_4.ds__year AS metric_time__year
+ , subq_4.ds__extract_year AS metric_time__extract_year
+ , subq_4.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_4.ds__extract_month AS metric_time__extract_month
+ , subq_4.ds__extract_day AS metric_time__extract_day
+ , subq_4.ds__extract_dow AS metric_time__extract_dow
+ , subq_4.ds__extract_doy AS metric_time__extract_doy
+ , subq_4.user
+ , subq_4.session
+ , subq_4.visit__user
+ , subq_4.visit__session
+ , subq_4.referrer_id
+ , subq_4.visit__referrer_id
+ , subq_4.visits
+ , subq_4.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_10011.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy
+ , visits_source_src_10011.referrer_id
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy
+ , visits_source_src_10011.referrer_id AS visit__referrer_id
+ , visits_source_src_10011.user_id AS user
+ , visits_source_src_10011.session_id AS session
+ , visits_source_src_10011.user_id AS visit__user
+ , visits_source_src_10011.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_4
+ ) subq_5
+ ) subq_6
+ INNER JOIN (
+ -- Add column with generated UUID
+ 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.buy__ds__day
+ , subq_8.buy__ds__week
+ , subq_8.buy__ds__month
+ , subq_8.buy__ds__quarter
+ , subq_8.buy__ds__year
+ , subq_8.buy__ds__extract_year
+ , subq_8.buy__ds__extract_quarter
+ , subq_8.buy__ds__extract_month
+ , subq_8.buy__ds__extract_day
+ , subq_8.buy__ds__extract_dow
+ , subq_8.buy__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session_id
+ , subq_8.buy__user
+ , subq_8.buy__session_id
+ , subq_8.buys
+ , subq_8.buyers
+ , uuid() AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.buy__ds__day
+ , subq_7.buy__ds__week
+ , subq_7.buy__ds__month
+ , subq_7.buy__ds__quarter
+ , subq_7.buy__ds__year
+ , subq_7.buy__ds__extract_year
+ , subq_7.buy__ds__extract_quarter
+ , subq_7.buy__ds__extract_month
+ , subq_7.buy__ds__extract_day
+ , subq_7.buy__ds__extract_dow
+ , subq_7.buy__ds__extract_doy
+ , subq_7.ds__day AS metric_time__day
+ , subq_7.ds__week AS metric_time__week
+ , subq_7.ds__month AS metric_time__month
+ , subq_7.ds__quarter AS metric_time__quarter
+ , subq_7.ds__year AS metric_time__year
+ , subq_7.ds__extract_year AS metric_time__extract_year
+ , subq_7.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_7.ds__extract_month AS metric_time__extract_month
+ , subq_7.ds__extract_day AS metric_time__extract_day
+ , subq_7.ds__extract_dow AS metric_time__extract_dow
+ , subq_7.ds__extract_doy AS metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session_id
+ , subq_7.buy__user
+ , subq_7.buy__session_id
+ , subq_7.buys
+ , subq_7.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_10002.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_10002.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_10002.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_10002.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_10002.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_10002.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_10002.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_10002.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_10002.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_10002.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_10002.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_10002.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_10002.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_10002.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_10002.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_10002.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_10002.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_10002.ds) AS buy__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_10002.ds) AS buy__ds__extract_doy
+ , buys_source_src_10002.user_id AS user
+ , buys_source_src_10002.session_id
+ , buys_source_src_10002.user_id AS buy__user
+ , buys_source_src_10002.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_10002
+ ) subq_7
+ ) subq_8
+ ) subq_9
+ ON
+ (subq_6.user = subq_9.user) AND ((subq_6.ds__day <= subq_9.ds__day))
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ GROUP BY
+ subq_12.visit__referrer_id
+ ) subq_13
+ ON
+ subq_3.visit__referrer_id = subq_13.visit__referrer_id
+ GROUP BY
+ COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id)
+) subq_14
diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0_optimized.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0_optimized.sql
new file mode 100644
index 0000000000..9f0493d406
--- /dev/null
+++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate__plan0_optimized.sql
@@ -0,0 +1,83 @@
+-- Compute Metrics via Expressions
+SELECT
+ visit__referrer_id
+ , CAST(buys AS DOUBLE) / CAST(NULLIF(visits, 0) AS DOUBLE) AS visit_buy_conversion_rate
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_18.visits) AS visits
+ , MAX(subq_28.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ visit__referrer_id
+ , SUM(visits) AS visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['visits', 'visit__referrer_id']
+ SELECT
+ referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_17
+ GROUP BY
+ visit__referrer_id
+ ) subq_18
+ FULL OUTER JOIN (
+ -- Find conversions for user within the range of INF
+ -- Pass Only Elements:
+ -- ['buys', 'visit__referrer_id']
+ -- Aggregate Measures
+ SELECT
+ visit__referrer_id
+ , SUM(buys) AS buys
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ first_value(subq_21.visits) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits
+ , first_value(subq_21.visit__referrer_id) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visit__referrer_id
+ , first_value(subq_21.ds__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day
+ , first_value(subq_21.user) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS user
+ , subq_24.mf_internal_uuid AS mf_internal_uuid
+ , subq_24.buys AS buys
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['visits', 'visit__referrer_id', 'ds__day', 'user']
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_21
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
+ -- Add column with generated UUID
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , 1 AS buys
+ , uuid() AS mf_internal_uuid
+ FROM ***************************.fct_buys buys_source_src_10002
+ ) subq_24
+ ON
+ (
+ subq_21.user = subq_24.user
+ ) AND (
+ (subq_21.ds__day <= subq_24.ds__day)
+ )
+ ) subq_25
+ GROUP BY
+ visit__referrer_id
+ ) subq_28
+ ON
+ subq_18.visit__referrer_id = subq_28.visit__referrer_id
+ GROUP BY
+ COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id)
+) subq_29
diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0.sql
new file mode 100644
index 0000000000..60b4af433e
--- /dev/null
+++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0.sql
@@ -0,0 +1,389 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ , CAST(subq_14.buys AS DOUBLE) / CAST(NULLIF(subq_14.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_by_session
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_3.metric_time__day, subq_13.metric_time__day) AS metric_time__day
+ , COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_3.visits) AS visits
+ , MAX(subq_13.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.visit__referrer_id
+ , SUM(subq_2.visits) AS visits
+ FROM (
+ -- Pass Only Elements:
+ -- ['visits', 'visit__referrer_id', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.visit__referrer_id
+ , subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_10011.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy
+ , visits_source_src_10011.referrer_id
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy
+ , visits_source_src_10011.referrer_id AS visit__referrer_id
+ , visits_source_src_10011.user_id AS user
+ , visits_source_src_10011.session_id AS session
+ , visits_source_src_10011.user_id AS visit__user
+ , visits_source_src_10011.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ , subq_2.visit__referrer_id
+ ) subq_3
+ FULL OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ subq_12.metric_time__day
+ , subq_12.visit__referrer_id
+ , SUM(subq_12.buys) AS buys
+ FROM (
+ -- Pass Only Elements:
+ -- ['buys', 'visit__referrer_id', 'metric_time__day']
+ SELECT
+ subq_11.metric_time__day
+ , subq_11.visit__referrer_id
+ , subq_11.buys
+ FROM (
+ -- Find conversions for user within the range of 7 day
+ SELECT
+ subq_10.ds__day
+ , subq_10.metric_time__day
+ , subq_10.user
+ , subq_10.session
+ , subq_10.visit__referrer_id
+ , subq_10.buys
+ , subq_10.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ first_value(subq_6.visits) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid, subq_9.session_id ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits
+ , first_value(subq_6.visit__referrer_id) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid, subq_9.session_id ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visit__referrer_id
+ , first_value(subq_6.ds__day) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid, subq_9.session_id ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day
+ , first_value(subq_6.metric_time__day) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid, subq_9.session_id ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS metric_time__day
+ , first_value(subq_6.user) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid, subq_9.session_id ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS user
+ , first_value(subq_6.session) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid, subq_9.session_id ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS session
+ , subq_9.mf_internal_uuid AS mf_internal_uuid
+ , subq_9.buys AS buys
+ FROM (
+ -- Pass Only Elements:
+ -- ['visits',
+ -- 'visit__referrer_id',
+ -- 'ds__day',
+ -- 'metric_time__day',
+ -- 'user',
+ -- 'session']
+ SELECT
+ subq_5.ds__day
+ , subq_5.metric_time__day
+ , subq_5.user
+ , subq_5.session
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_4.ds__day
+ , subq_4.ds__week
+ , subq_4.ds__month
+ , subq_4.ds__quarter
+ , subq_4.ds__year
+ , subq_4.ds__extract_year
+ , subq_4.ds__extract_quarter
+ , subq_4.ds__extract_month
+ , subq_4.ds__extract_day
+ , subq_4.ds__extract_dow
+ , subq_4.ds__extract_doy
+ , subq_4.visit__ds__day
+ , subq_4.visit__ds__week
+ , subq_4.visit__ds__month
+ , subq_4.visit__ds__quarter
+ , subq_4.visit__ds__year
+ , subq_4.visit__ds__extract_year
+ , subq_4.visit__ds__extract_quarter
+ , subq_4.visit__ds__extract_month
+ , subq_4.visit__ds__extract_day
+ , subq_4.visit__ds__extract_dow
+ , subq_4.visit__ds__extract_doy
+ , subq_4.ds__day AS metric_time__day
+ , subq_4.ds__week AS metric_time__week
+ , subq_4.ds__month AS metric_time__month
+ , subq_4.ds__quarter AS metric_time__quarter
+ , subq_4.ds__year AS metric_time__year
+ , subq_4.ds__extract_year AS metric_time__extract_year
+ , subq_4.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_4.ds__extract_month AS metric_time__extract_month
+ , subq_4.ds__extract_day AS metric_time__extract_day
+ , subq_4.ds__extract_dow AS metric_time__extract_dow
+ , subq_4.ds__extract_doy AS metric_time__extract_doy
+ , subq_4.user
+ , subq_4.session
+ , subq_4.visit__user
+ , subq_4.visit__session
+ , subq_4.referrer_id
+ , subq_4.visit__referrer_id
+ , subq_4.visits
+ , subq_4.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_10011.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy
+ , visits_source_src_10011.referrer_id
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy
+ , visits_source_src_10011.referrer_id AS visit__referrer_id
+ , visits_source_src_10011.user_id AS user
+ , visits_source_src_10011.session_id AS session
+ , visits_source_src_10011.user_id AS visit__user
+ , visits_source_src_10011.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_4
+ ) subq_5
+ ) subq_6
+ INNER JOIN (
+ -- Add column with generated UUID
+ 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.buy__ds__day
+ , subq_8.buy__ds__week
+ , subq_8.buy__ds__month
+ , subq_8.buy__ds__quarter
+ , subq_8.buy__ds__year
+ , subq_8.buy__ds__extract_year
+ , subq_8.buy__ds__extract_quarter
+ , subq_8.buy__ds__extract_month
+ , subq_8.buy__ds__extract_day
+ , subq_8.buy__ds__extract_dow
+ , subq_8.buy__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session_id
+ , subq_8.buy__user
+ , subq_8.buy__session_id
+ , subq_8.buys
+ , subq_8.buyers
+ , uuid() AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.buy__ds__day
+ , subq_7.buy__ds__week
+ , subq_7.buy__ds__month
+ , subq_7.buy__ds__quarter
+ , subq_7.buy__ds__year
+ , subq_7.buy__ds__extract_year
+ , subq_7.buy__ds__extract_quarter
+ , subq_7.buy__ds__extract_month
+ , subq_7.buy__ds__extract_day
+ , subq_7.buy__ds__extract_dow
+ , subq_7.buy__ds__extract_doy
+ , subq_7.ds__day AS metric_time__day
+ , subq_7.ds__week AS metric_time__week
+ , subq_7.ds__month AS metric_time__month
+ , subq_7.ds__quarter AS metric_time__quarter
+ , subq_7.ds__year AS metric_time__year
+ , subq_7.ds__extract_year AS metric_time__extract_year
+ , subq_7.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_7.ds__extract_month AS metric_time__extract_month
+ , subq_7.ds__extract_day AS metric_time__extract_day
+ , subq_7.ds__extract_dow AS metric_time__extract_dow
+ , subq_7.ds__extract_doy AS metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session_id
+ , subq_7.buy__user
+ , subq_7.buy__session_id
+ , subq_7.buys
+ , subq_7.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_10002.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_10002.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_10002.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_10002.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_10002.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_10002.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_10002.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_10002.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_10002.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_10002.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_10002.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_10002.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_10002.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_10002.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_10002.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_10002.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_10002.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_10002.ds) AS buy__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_10002.ds) AS buy__ds__extract_doy
+ , buys_source_src_10002.user_id AS user
+ , buys_source_src_10002.session_id
+ , buys_source_src_10002.user_id AS buy__user
+ , buys_source_src_10002.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_10002
+ ) subq_7
+ ) subq_8
+ ) subq_9
+ ON
+ (
+ subq_6.user = subq_9.user
+ ) AND (
+ subq_6.session = subq_9.session_id
+ ) AND (
+ (
+ subq_6.ds__day <= subq_9.ds__day
+ ) AND (
+ subq_6.ds__day > DATE_ADD('day', -7, subq_9.ds__day)
+ )
+ )
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ GROUP BY
+ subq_12.metric_time__day
+ , subq_12.visit__referrer_id
+ ) subq_13
+ ON
+ (
+ subq_3.visit__referrer_id = subq_13.visit__referrer_id
+ ) AND (
+ subq_3.metric_time__day = subq_13.metric_time__day
+ )
+ GROUP BY
+ COALESCE(subq_3.metric_time__day, subq_13.metric_time__day)
+ , COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id)
+) subq_14
diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0_optimized.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0_optimized.sql
new file mode 100644
index 0000000000..dd31bc8ef0
--- /dev/null
+++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_constant_properties__plan0_optimized.sql
@@ -0,0 +1,111 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , visit__referrer_id
+ , CAST(buys AS DOUBLE) / CAST(NULLIF(visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_by_session
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_18.metric_time__day, subq_28.metric_time__day) AS metric_time__day
+ , COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_18.visits) AS visits
+ , MAX(subq_28.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ metric_time__day
+ , visit__referrer_id
+ , SUM(visits) AS visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['visits', 'visit__referrer_id', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_17
+ GROUP BY
+ metric_time__day
+ , visit__referrer_id
+ ) subq_18
+ FULL OUTER JOIN (
+ -- Find conversions for user within the range of 7 day
+ -- Pass Only Elements:
+ -- ['buys', 'visit__referrer_id', 'metric_time__day']
+ -- Aggregate Measures
+ SELECT
+ metric_time__day
+ , visit__referrer_id
+ , SUM(buys) AS buys
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ first_value(subq_21.visits) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid, subq_24.session_id ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits
+ , first_value(subq_21.visit__referrer_id) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid, subq_24.session_id ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visit__referrer_id
+ , first_value(subq_21.ds__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid, subq_24.session_id ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day
+ , first_value(subq_21.metric_time__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid, subq_24.session_id ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS metric_time__day
+ , first_value(subq_21.user) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid, subq_24.session_id ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS user
+ , first_value(subq_21.session) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid, subq_24.session_id ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS session
+ , subq_24.mf_internal_uuid AS mf_internal_uuid
+ , subq_24.buys AS buys
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['visits',
+ -- 'visit__referrer_id',
+ -- 'ds__day',
+ -- 'metric_time__day',
+ -- 'user',
+ -- 'session']
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) AS metric_time__day
+ , user_id AS user
+ , session_id AS session
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_21
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
+ -- Add column with generated UUID
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , session_id
+ , 1 AS buys
+ , uuid() AS mf_internal_uuid
+ FROM ***************************.fct_buys buys_source_src_10002
+ ) subq_24
+ ON
+ (
+ subq_21.user = subq_24.user
+ ) AND (
+ subq_21.session = subq_24.session_id
+ ) AND (
+ (
+ subq_21.ds__day <= subq_24.ds__day
+ ) AND (
+ subq_21.ds__day > DATE_ADD('day', -7, subq_24.ds__day)
+ )
+ )
+ ) subq_25
+ GROUP BY
+ metric_time__day
+ , visit__referrer_id
+ ) subq_28
+ ON
+ (
+ subq_18.visit__referrer_id = subq_28.visit__referrer_id
+ ) AND (
+ subq_18.metric_time__day = subq_28.metric_time__day
+ )
+ GROUP BY
+ COALESCE(subq_18.metric_time__day, subq_28.metric_time__day)
+ , COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id)
+) subq_29
diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0.sql
new file mode 100644
index 0000000000..7ca65cd123
--- /dev/null
+++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0.sql
@@ -0,0 +1,346 @@
+-- Compute Metrics via Expressions
+SELECT
+ CAST(subq_14.buys AS DOUBLE) / CAST(NULLIF(subq_14.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ MAX(subq_3.visits) AS visits
+ , MAX(subq_13.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_2.visits) AS visits
+ FROM (
+ -- Pass Only Elements:
+ -- ['visits']
+ SELECT
+ subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_10011.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy
+ , visits_source_src_10011.referrer_id
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy
+ , visits_source_src_10011.referrer_id AS visit__referrer_id
+ , visits_source_src_10011.user_id AS user
+ , visits_source_src_10011.session_id AS session
+ , visits_source_src_10011.user_id AS visit__user
+ , visits_source_src_10011.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ ) subq_3
+ CROSS JOIN (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_12.buys) AS buys
+ FROM (
+ -- Pass Only Elements:
+ -- ['buys']
+ SELECT
+ subq_11.buys
+ FROM (
+ -- Find conversions for user within the range of 7 day
+ SELECT
+ subq_10.ds__day
+ , subq_10.user
+ , subq_10.buys
+ , subq_10.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ first_value(subq_6.visits) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits
+ , first_value(subq_6.ds__day) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day
+ , first_value(subq_6.user) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS user
+ , subq_9.mf_internal_uuid AS mf_internal_uuid
+ , subq_9.buys AS buys
+ FROM (
+ -- Pass Only Elements:
+ -- ['visits', 'ds__day', 'user']
+ SELECT
+ subq_5.ds__day
+ , subq_5.user
+ , subq_5.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_4.ds__day
+ , subq_4.ds__week
+ , subq_4.ds__month
+ , subq_4.ds__quarter
+ , subq_4.ds__year
+ , subq_4.ds__extract_year
+ , subq_4.ds__extract_quarter
+ , subq_4.ds__extract_month
+ , subq_4.ds__extract_day
+ , subq_4.ds__extract_dow
+ , subq_4.ds__extract_doy
+ , subq_4.visit__ds__day
+ , subq_4.visit__ds__week
+ , subq_4.visit__ds__month
+ , subq_4.visit__ds__quarter
+ , subq_4.visit__ds__year
+ , subq_4.visit__ds__extract_year
+ , subq_4.visit__ds__extract_quarter
+ , subq_4.visit__ds__extract_month
+ , subq_4.visit__ds__extract_day
+ , subq_4.visit__ds__extract_dow
+ , subq_4.visit__ds__extract_doy
+ , subq_4.ds__day AS metric_time__day
+ , subq_4.ds__week AS metric_time__week
+ , subq_4.ds__month AS metric_time__month
+ , subq_4.ds__quarter AS metric_time__quarter
+ , subq_4.ds__year AS metric_time__year
+ , subq_4.ds__extract_year AS metric_time__extract_year
+ , subq_4.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_4.ds__extract_month AS metric_time__extract_month
+ , subq_4.ds__extract_day AS metric_time__extract_day
+ , subq_4.ds__extract_dow AS metric_time__extract_dow
+ , subq_4.ds__extract_doy AS metric_time__extract_doy
+ , subq_4.user
+ , subq_4.session
+ , subq_4.visit__user
+ , subq_4.visit__session
+ , subq_4.referrer_id
+ , subq_4.visit__referrer_id
+ , subq_4.visits
+ , subq_4.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_10011.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy
+ , visits_source_src_10011.referrer_id
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy
+ , visits_source_src_10011.referrer_id AS visit__referrer_id
+ , visits_source_src_10011.user_id AS user
+ , visits_source_src_10011.session_id AS session
+ , visits_source_src_10011.user_id AS visit__user
+ , visits_source_src_10011.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_4
+ ) subq_5
+ ) subq_6
+ INNER JOIN (
+ -- Add column with generated UUID
+ 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.buy__ds__day
+ , subq_8.buy__ds__week
+ , subq_8.buy__ds__month
+ , subq_8.buy__ds__quarter
+ , subq_8.buy__ds__year
+ , subq_8.buy__ds__extract_year
+ , subq_8.buy__ds__extract_quarter
+ , subq_8.buy__ds__extract_month
+ , subq_8.buy__ds__extract_day
+ , subq_8.buy__ds__extract_dow
+ , subq_8.buy__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session_id
+ , subq_8.buy__user
+ , subq_8.buy__session_id
+ , subq_8.buys
+ , subq_8.buyers
+ , uuid() AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.buy__ds__day
+ , subq_7.buy__ds__week
+ , subq_7.buy__ds__month
+ , subq_7.buy__ds__quarter
+ , subq_7.buy__ds__year
+ , subq_7.buy__ds__extract_year
+ , subq_7.buy__ds__extract_quarter
+ , subq_7.buy__ds__extract_month
+ , subq_7.buy__ds__extract_day
+ , subq_7.buy__ds__extract_dow
+ , subq_7.buy__ds__extract_doy
+ , subq_7.ds__day AS metric_time__day
+ , subq_7.ds__week AS metric_time__week
+ , subq_7.ds__month AS metric_time__month
+ , subq_7.ds__quarter AS metric_time__quarter
+ , subq_7.ds__year AS metric_time__year
+ , subq_7.ds__extract_year AS metric_time__extract_year
+ , subq_7.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_7.ds__extract_month AS metric_time__extract_month
+ , subq_7.ds__extract_day AS metric_time__extract_day
+ , subq_7.ds__extract_dow AS metric_time__extract_dow
+ , subq_7.ds__extract_doy AS metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session_id
+ , subq_7.buy__user
+ , subq_7.buy__session_id
+ , subq_7.buys
+ , subq_7.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_10002.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_10002.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_10002.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_10002.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_10002.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_10002.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_10002.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_10002.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_10002.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_10002.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_10002.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_10002.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_10002.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_10002.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_10002.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_10002.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_10002.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_10002.ds) AS buy__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_10002.ds) AS buy__ds__extract_doy
+ , buys_source_src_10002.user_id AS user
+ , buys_source_src_10002.session_id
+ , buys_source_src_10002.user_id AS buy__user
+ , buys_source_src_10002.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_10002
+ ) subq_7
+ ) subq_8
+ ) subq_9
+ ON
+ (
+ subq_6.user = subq_9.user
+ ) AND (
+ (
+ subq_6.ds__day <= subq_9.ds__day
+ ) AND (
+ subq_6.ds__day > DATE_ADD('day', -7, subq_9.ds__day)
+ )
+ )
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ ) subq_13
+) subq_14
diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0_optimized.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0_optimized.sql
new file mode 100644
index 0000000000..69b10a78a8
--- /dev/null
+++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_no_group_by__plan0_optimized.sql
@@ -0,0 +1,63 @@
+-- Combine Aggregated Outputs
+-- Compute Metrics via Expressions
+SELECT
+ CAST(MAX(subq_28.buys) AS DOUBLE) / CAST(NULLIF(MAX(subq_18.visits), 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['visits']
+ -- Aggregate Measures
+ SELECT
+ SUM(1) AS visits
+ FROM ***************************.fct_visits visits_source_src_10011
+) subq_18
+CROSS JOIN (
+ -- Find conversions for user within the range of 7 day
+ -- Pass Only Elements:
+ -- ['buys']
+ -- Aggregate Measures
+ SELECT
+ SUM(buys) AS buys
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ first_value(subq_21.visits) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits
+ , first_value(subq_21.ds__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day
+ , first_value(subq_21.user) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS user
+ , subq_24.mf_internal_uuid AS mf_internal_uuid
+ , subq_24.buys AS buys
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['visits', 'ds__day', 'user']
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_21
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
+ -- Add column with generated UUID
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , 1 AS buys
+ , uuid() AS mf_internal_uuid
+ FROM ***************************.fct_buys buys_source_src_10002
+ ) subq_24
+ ON
+ (
+ subq_21.user = subq_24.user
+ ) AND (
+ (
+ subq_21.ds__day <= subq_24.ds__day
+ ) AND (
+ subq_21.ds__day > DATE_ADD('day', -7, subq_24.ds__day)
+ )
+ )
+ ) subq_25
+) subq_28
diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0.sql
new file mode 100644
index 0000000000..2ecf6c63a9
--- /dev/null
+++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0.sql
@@ -0,0 +1,379 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_14.metric_time__day
+ , subq_14.visit__referrer_id
+ , CAST(subq_14.buys AS DOUBLE) / CAST(NULLIF(subq_14.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_3.metric_time__day, subq_13.metric_time__day) AS metric_time__day
+ , COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_3.visits) AS visits
+ , MAX(subq_13.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.visit__referrer_id
+ , SUM(subq_2.visits) AS visits
+ FROM (
+ -- Pass Only Elements:
+ -- ['visits', 'visit__referrer_id', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.visit__referrer_id
+ , subq_1.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.visit__ds__day
+ , subq_0.visit__ds__week
+ , subq_0.visit__ds__month
+ , subq_0.visit__ds__quarter
+ , subq_0.visit__ds__year
+ , subq_0.visit__ds__extract_year
+ , subq_0.visit__ds__extract_quarter
+ , subq_0.visit__ds__extract_month
+ , subq_0.visit__ds__extract_day
+ , subq_0.visit__ds__extract_dow
+ , subq_0.visit__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.session
+ , subq_0.visit__user
+ , subq_0.visit__session
+ , subq_0.referrer_id
+ , subq_0.visit__referrer_id
+ , subq_0.visits
+ , subq_0.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_10011.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy
+ , visits_source_src_10011.referrer_id
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy
+ , visits_source_src_10011.referrer_id AS visit__referrer_id
+ , visits_source_src_10011.user_id AS user
+ , visits_source_src_10011.session_id AS session
+ , visits_source_src_10011.user_id AS visit__user
+ , visits_source_src_10011.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ , subq_2.visit__referrer_id
+ ) subq_3
+ FULL OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ subq_12.metric_time__day
+ , subq_12.visit__referrer_id
+ , SUM(subq_12.buys) AS buys
+ FROM (
+ -- Pass Only Elements:
+ -- ['buys', 'visit__referrer_id', 'metric_time__day']
+ SELECT
+ subq_11.metric_time__day
+ , subq_11.visit__referrer_id
+ , subq_11.buys
+ FROM (
+ -- Find conversions for user within the range of 7 day
+ SELECT
+ subq_10.ds__day
+ , subq_10.metric_time__day
+ , subq_10.user
+ , subq_10.visit__referrer_id
+ , subq_10.buys
+ , subq_10.visits
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ first_value(subq_6.visits) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits
+ , first_value(subq_6.visit__referrer_id) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visit__referrer_id
+ , first_value(subq_6.ds__day) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day
+ , first_value(subq_6.metric_time__day) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS metric_time__day
+ , first_value(subq_6.user) OVER (PARTITION BY subq_9.user, subq_9.ds__day, subq_9.mf_internal_uuid ORDER BY subq_6.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS user
+ , subq_9.mf_internal_uuid AS mf_internal_uuid
+ , subq_9.buys AS buys
+ FROM (
+ -- Pass Only Elements:
+ -- ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ subq_5.ds__day
+ , subq_5.metric_time__day
+ , subq_5.user
+ , subq_5.visit__referrer_id
+ , subq_5.visits
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_4.ds__day
+ , subq_4.ds__week
+ , subq_4.ds__month
+ , subq_4.ds__quarter
+ , subq_4.ds__year
+ , subq_4.ds__extract_year
+ , subq_4.ds__extract_quarter
+ , subq_4.ds__extract_month
+ , subq_4.ds__extract_day
+ , subq_4.ds__extract_dow
+ , subq_4.ds__extract_doy
+ , subq_4.visit__ds__day
+ , subq_4.visit__ds__week
+ , subq_4.visit__ds__month
+ , subq_4.visit__ds__quarter
+ , subq_4.visit__ds__year
+ , subq_4.visit__ds__extract_year
+ , subq_4.visit__ds__extract_quarter
+ , subq_4.visit__ds__extract_month
+ , subq_4.visit__ds__extract_day
+ , subq_4.visit__ds__extract_dow
+ , subq_4.visit__ds__extract_doy
+ , subq_4.ds__day AS metric_time__day
+ , subq_4.ds__week AS metric_time__week
+ , subq_4.ds__month AS metric_time__month
+ , subq_4.ds__quarter AS metric_time__quarter
+ , subq_4.ds__year AS metric_time__year
+ , subq_4.ds__extract_year AS metric_time__extract_year
+ , subq_4.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_4.ds__extract_month AS metric_time__extract_month
+ , subq_4.ds__extract_day AS metric_time__extract_day
+ , subq_4.ds__extract_dow AS metric_time__extract_dow
+ , subq_4.ds__extract_doy AS metric_time__extract_doy
+ , subq_4.user
+ , subq_4.session
+ , subq_4.visit__user
+ , subq_4.visit__session
+ , subq_4.referrer_id
+ , subq_4.visit__referrer_id
+ , subq_4.visits
+ , subq_4.visitors
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ SELECT
+ 1 AS visits
+ , visits_source_src_10011.user_id AS visitors
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS ds__extract_doy
+ , visits_source_src_10011.referrer_id
+ , DATE_TRUNC('day', visits_source_src_10011.ds) AS visit__ds__day
+ , DATE_TRUNC('week', visits_source_src_10011.ds) AS visit__ds__week
+ , DATE_TRUNC('month', visits_source_src_10011.ds) AS visit__ds__month
+ , DATE_TRUNC('quarter', visits_source_src_10011.ds) AS visit__ds__quarter
+ , DATE_TRUNC('year', visits_source_src_10011.ds) AS visit__ds__year
+ , EXTRACT(year FROM visits_source_src_10011.ds) AS visit__ds__extract_year
+ , EXTRACT(quarter FROM visits_source_src_10011.ds) AS visit__ds__extract_quarter
+ , EXTRACT(month FROM visits_source_src_10011.ds) AS visit__ds__extract_month
+ , EXTRACT(day FROM visits_source_src_10011.ds) AS visit__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM visits_source_src_10011.ds) AS visit__ds__extract_dow
+ , EXTRACT(doy FROM visits_source_src_10011.ds) AS visit__ds__extract_doy
+ , visits_source_src_10011.referrer_id AS visit__referrer_id
+ , visits_source_src_10011.user_id AS user
+ , visits_source_src_10011.session_id AS session
+ , visits_source_src_10011.user_id AS visit__user
+ , visits_source_src_10011.session_id AS visit__session
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_4
+ ) subq_5
+ ) subq_6
+ INNER JOIN (
+ -- Add column with generated UUID
+ 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.buy__ds__day
+ , subq_8.buy__ds__week
+ , subq_8.buy__ds__month
+ , subq_8.buy__ds__quarter
+ , subq_8.buy__ds__year
+ , subq_8.buy__ds__extract_year
+ , subq_8.buy__ds__extract_quarter
+ , subq_8.buy__ds__extract_month
+ , subq_8.buy__ds__extract_day
+ , subq_8.buy__ds__extract_dow
+ , subq_8.buy__ds__extract_doy
+ , subq_8.metric_time__day
+ , subq_8.metric_time__week
+ , subq_8.metric_time__month
+ , subq_8.metric_time__quarter
+ , subq_8.metric_time__year
+ , subq_8.metric_time__extract_year
+ , subq_8.metric_time__extract_quarter
+ , subq_8.metric_time__extract_month
+ , subq_8.metric_time__extract_day
+ , subq_8.metric_time__extract_dow
+ , subq_8.metric_time__extract_doy
+ , subq_8.user
+ , subq_8.session_id
+ , subq_8.buy__user
+ , subq_8.buy__session_id
+ , subq_8.buys
+ , subq_8.buyers
+ , uuid() AS mf_internal_uuid
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.buy__ds__day
+ , subq_7.buy__ds__week
+ , subq_7.buy__ds__month
+ , subq_7.buy__ds__quarter
+ , subq_7.buy__ds__year
+ , subq_7.buy__ds__extract_year
+ , subq_7.buy__ds__extract_quarter
+ , subq_7.buy__ds__extract_month
+ , subq_7.buy__ds__extract_day
+ , subq_7.buy__ds__extract_dow
+ , subq_7.buy__ds__extract_doy
+ , subq_7.ds__day AS metric_time__day
+ , subq_7.ds__week AS metric_time__week
+ , subq_7.ds__month AS metric_time__month
+ , subq_7.ds__quarter AS metric_time__quarter
+ , subq_7.ds__year AS metric_time__year
+ , subq_7.ds__extract_year AS metric_time__extract_year
+ , subq_7.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_7.ds__extract_month AS metric_time__extract_month
+ , subq_7.ds__extract_day AS metric_time__extract_day
+ , subq_7.ds__extract_dow AS metric_time__extract_dow
+ , subq_7.ds__extract_doy AS metric_time__extract_doy
+ , subq_7.user
+ , subq_7.session_id
+ , subq_7.buy__user
+ , subq_7.buy__session_id
+ , subq_7.buys
+ , subq_7.buyers
+ FROM (
+ -- Read Elements From Semantic Model 'buys_source'
+ SELECT
+ 1 AS buys
+ , buys_source_src_10002.user_id AS buyers
+ , DATE_TRUNC('day', buys_source_src_10002.ds) AS ds__day
+ , DATE_TRUNC('week', buys_source_src_10002.ds) AS ds__week
+ , DATE_TRUNC('month', buys_source_src_10002.ds) AS ds__month
+ , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS ds__quarter
+ , DATE_TRUNC('year', buys_source_src_10002.ds) AS ds__year
+ , EXTRACT(year FROM buys_source_src_10002.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_10002.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_10002.ds) AS ds__extract_month
+ , EXTRACT(day FROM buys_source_src_10002.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_10002.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', buys_source_src_10002.ds) AS buy__ds__day
+ , DATE_TRUNC('week', buys_source_src_10002.ds) AS buy__ds__week
+ , DATE_TRUNC('month', buys_source_src_10002.ds) AS buy__ds__month
+ , DATE_TRUNC('quarter', buys_source_src_10002.ds) AS buy__ds__quarter
+ , DATE_TRUNC('year', buys_source_src_10002.ds) AS buy__ds__year
+ , EXTRACT(year FROM buys_source_src_10002.ds) AS buy__ds__extract_year
+ , EXTRACT(quarter FROM buys_source_src_10002.ds) AS buy__ds__extract_quarter
+ , EXTRACT(month FROM buys_source_src_10002.ds) AS buy__ds__extract_month
+ , EXTRACT(day FROM buys_source_src_10002.ds) AS buy__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM buys_source_src_10002.ds) AS buy__ds__extract_dow
+ , EXTRACT(doy FROM buys_source_src_10002.ds) AS buy__ds__extract_doy
+ , buys_source_src_10002.user_id AS user
+ , buys_source_src_10002.session_id
+ , buys_source_src_10002.user_id AS buy__user
+ , buys_source_src_10002.session_id AS buy__session_id
+ FROM ***************************.fct_buys buys_source_src_10002
+ ) subq_7
+ ) subq_8
+ ) subq_9
+ ON
+ (
+ subq_6.user = subq_9.user
+ ) AND (
+ (
+ subq_6.ds__day <= subq_9.ds__day
+ ) AND (
+ subq_6.ds__day > DATE_ADD('day', -7, subq_9.ds__day)
+ )
+ )
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ GROUP BY
+ subq_12.metric_time__day
+ , subq_12.visit__referrer_id
+ ) subq_13
+ ON
+ (
+ subq_3.visit__referrer_id = subq_13.visit__referrer_id
+ ) AND (
+ subq_3.metric_time__day = subq_13.metric_time__day
+ )
+ GROUP BY
+ COALESCE(subq_3.metric_time__day, subq_13.metric_time__day)
+ , COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id)
+) subq_14
diff --git a/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0_optimized.sql b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0_optimized.sql
new file mode 100644
index 0000000000..358169cce7
--- /dev/null
+++ b/metricflow/test/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/Trino/test_conversion_rate_with_window__plan0_optimized.sql
@@ -0,0 +1,101 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , visit__referrer_id
+ , CAST(buys AS DOUBLE) / CAST(NULLIF(visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_18.metric_time__day, subq_28.metric_time__day) AS metric_time__day
+ , COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id) AS visit__referrer_id
+ , MAX(subq_18.visits) AS visits
+ , MAX(subq_28.buys) AS buys
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ metric_time__day
+ , visit__referrer_id
+ , SUM(visits) AS visits
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['visits', 'visit__referrer_id', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_17
+ GROUP BY
+ metric_time__day
+ , visit__referrer_id
+ ) subq_18
+ FULL OUTER JOIN (
+ -- Find conversions for user within the range of 7 day
+ -- Pass Only Elements:
+ -- ['buys', 'visit__referrer_id', 'metric_time__day']
+ -- Aggregate Measures
+ SELECT
+ metric_time__day
+ , visit__referrer_id
+ , SUM(buys) AS buys
+ FROM (
+ -- Dedupe the fanout with mf_internal_uuid in the conversion data set
+ SELECT DISTINCT
+ first_value(subq_21.visits) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visits
+ , first_value(subq_21.visit__referrer_id) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS visit__referrer_id
+ , first_value(subq_21.ds__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS ds__day
+ , first_value(subq_21.metric_time__day) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS metric_time__day
+ , first_value(subq_21.user) OVER (PARTITION BY subq_24.user, subq_24.ds__day, subq_24.mf_internal_uuid ORDER BY subq_21.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS user
+ , subq_24.mf_internal_uuid AS mf_internal_uuid
+ , subq_24.buys AS buys
+ FROM (
+ -- Read Elements From Semantic Model 'visits_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user']
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) AS metric_time__day
+ , user_id AS user
+ , referrer_id AS visit__referrer_id
+ , 1 AS visits
+ FROM ***************************.fct_visits visits_source_src_10011
+ ) subq_21
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'buys_source'
+ -- Metric Time Dimension 'ds'
+ -- Add column with generated UUID
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , user_id AS user
+ , 1 AS buys
+ , uuid() AS mf_internal_uuid
+ FROM ***************************.fct_buys buys_source_src_10002
+ ) subq_24
+ ON
+ (
+ subq_21.user = subq_24.user
+ ) AND (
+ (
+ subq_21.ds__day <= subq_24.ds__day
+ ) AND (
+ subq_21.ds__day > DATE_ADD('day', -7, subq_24.ds__day)
+ )
+ )
+ ) subq_25
+ GROUP BY
+ metric_time__day
+ , visit__referrer_id
+ ) subq_28
+ ON
+ (
+ subq_18.visit__referrer_id = subq_28.visit__referrer_id
+ ) AND (
+ subq_18.metric_time__day = subq_28.metric_time__day
+ )
+ GROUP BY
+ COALESCE(subq_18.metric_time__day, subq_28.metric_time__day)
+ , COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id)
+) subq_29
diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql
new file mode 100644
index 0000000000..b615260818
--- /dev/null
+++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_query_semantic_model__plan0.sql
@@ -0,0 +1,28 @@
+-- Read Elements From Semantic Model 'revenue'
+SELECT
+ revenue_src_10007.revenue AS txn_revenue
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy
+ , revenue_src_10007.user_id AS user
+ , revenue_src_10007.user_id AS company__user
+FROM ***************************.fct_revenue revenue_src_10007
diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql
new file mode 100644
index 0000000000..26ee6990b0
--- /dev/null
+++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_with_measures__plan0.sql
@@ -0,0 +1,53 @@
+-- Read Elements From Semantic Model 'id_verifications'
+SELECT
+ 1 AS identity_verifications
+ , DATE_TRUNC('day', id_verifications_src_10004.ds) AS ds__day
+ , DATE_TRUNC('week', id_verifications_src_10004.ds) AS ds__week
+ , DATE_TRUNC('month', id_verifications_src_10004.ds) AS ds__month
+ , DATE_TRUNC('quarter', id_verifications_src_10004.ds) AS ds__quarter
+ , DATE_TRUNC('year', id_verifications_src_10004.ds) AS ds__year
+ , EXTRACT(year FROM id_verifications_src_10004.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM id_verifications_src_10004.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM id_verifications_src_10004.ds) AS ds__extract_month
+ , EXTRACT(day FROM id_verifications_src_10004.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM id_verifications_src_10004.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_doy
+ , id_verifications_src_10004.verification_type
+ , DATE_TRUNC('day', id_verifications_src_10004.ds) AS verification__ds__day
+ , DATE_TRUNC('week', id_verifications_src_10004.ds) AS verification__ds__week
+ , DATE_TRUNC('month', id_verifications_src_10004.ds) AS verification__ds__month
+ , DATE_TRUNC('quarter', id_verifications_src_10004.ds) AS verification__ds__quarter
+ , DATE_TRUNC('year', id_verifications_src_10004.ds) AS verification__ds__year
+ , EXTRACT(year FROM id_verifications_src_10004.ds) AS verification__ds__extract_year
+ , EXTRACT(quarter FROM id_verifications_src_10004.ds) AS verification__ds__extract_quarter
+ , EXTRACT(month FROM id_verifications_src_10004.ds) AS verification__ds__extract_month
+ , EXTRACT(day FROM id_verifications_src_10004.ds) AS verification__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds) AS verification__ds__extract_dow
+ , EXTRACT(doy FROM id_verifications_src_10004.ds) AS verification__ds__extract_doy
+ , DATE_TRUNC('day', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__day
+ , DATE_TRUNC('week', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__week
+ , DATE_TRUNC('month', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__month
+ , DATE_TRUNC('quarter', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__quarter
+ , DATE_TRUNC('year', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__year
+ , EXTRACT(year FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_month
+ , EXTRACT(day FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_doy
+ , id_verifications_src_10004.verification_type AS verification__verification_type
+ , id_verifications_src_10004.verification_id AS verification
+ , id_verifications_src_10004.user_id AS user
+ , id_verifications_src_10004.user_id AS verification__user
+FROM ***************************.fct_id_verifications id_verifications_src_10004
diff --git a/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql
new file mode 100644
index 0000000000..d14cc5b651
--- /dev/null
+++ b/metricflow/test/snapshots/test_convert_semantic_model.py/SqlQueryPlan/Trino/test_convert_table_semantic_model_without_measures__plan0.sql
@@ -0,0 +1,28 @@
+-- Read Elements From Semantic Model 'users_latest'
+SELECT
+ DATE_TRUNC('day', users_latest_src_10009.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_10009.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_10009.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_10009.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_10009.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10009.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10009.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_10009.ds) AS ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10009.ds) AS ds_latest__extract_doy
+ , users_latest_src_10009.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_10009.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_10009.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_10009.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_10009.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_10009.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10009.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10009.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_10009.ds) AS user__ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10009.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_10009.home_state_latest AS user__home_state_latest
+ , users_latest_src_10009.user_id AS user
+FROM ***************************.dim_users_latest users_latest_src_10009
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql
new file mode 100644
index 0000000000..2f9b5fe681
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0.sql
@@ -0,0 +1,89 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_3.ds__month
+ , subq_3.txn_revenue AS trailing_2_months_revenue
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.ds__month
+ , SUM(subq_2.txn_revenue) AS txn_revenue
+ FROM (
+ -- Pass Only Elements:
+ -- ['txn_revenue', 'ds__month']
+ SELECT
+ subq_1.ds__month
+ , subq_1.txn_revenue
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.company__ds__day
+ , subq_0.company__ds__week
+ , subq_0.company__ds__month
+ , subq_0.company__ds__quarter
+ , subq_0.company__ds__year
+ , subq_0.company__ds__extract_year
+ , subq_0.company__ds__extract_quarter
+ , subq_0.company__ds__extract_month
+ , subq_0.company__ds__extract_day
+ , subq_0.company__ds__extract_dow
+ , subq_0.company__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.company__user
+ , subq_0.txn_revenue
+ FROM (
+ -- Read Elements From Semantic Model 'revenue'
+ SELECT
+ revenue_src_10007.revenue AS txn_revenue
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy
+ , revenue_src_10007.user_id AS user
+ , revenue_src_10007.user_id AS company__user
+ FROM ***************************.fct_revenue revenue_src_10007
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.ds__month
+) subq_3
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql
new file mode 100644
index 0000000000..efe2244b0f
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric__plan0_optimized.sql
@@ -0,0 +1,12 @@
+-- Read Elements From Semantic Model 'revenue'
+-- Metric Time Dimension 'ds'
+-- Pass Only Elements:
+-- ['txn_revenue', 'ds__month']
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ DATE_TRUNC('month', created_at) AS ds__month
+ , SUM(revenue) AS trailing_2_months_revenue
+FROM ***************************.fct_revenue revenue_src_10007
+GROUP BY
+ DATE_TRUNC('month', created_at)
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql
new file mode 100644
index 0000000000..ca08f80e45
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0.sql
@@ -0,0 +1,89 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_3.ds__month
+ , subq_3.txn_revenue AS revenue_mtd
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.ds__month
+ , SUM(subq_2.txn_revenue) AS txn_revenue
+ FROM (
+ -- Pass Only Elements:
+ -- ['txn_revenue', 'ds__month']
+ SELECT
+ subq_1.ds__month
+ , subq_1.txn_revenue
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.company__ds__day
+ , subq_0.company__ds__week
+ , subq_0.company__ds__month
+ , subq_0.company__ds__quarter
+ , subq_0.company__ds__year
+ , subq_0.company__ds__extract_year
+ , subq_0.company__ds__extract_quarter
+ , subq_0.company__ds__extract_month
+ , subq_0.company__ds__extract_day
+ , subq_0.company__ds__extract_dow
+ , subq_0.company__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.company__user
+ , subq_0.txn_revenue
+ FROM (
+ -- Read Elements From Semantic Model 'revenue'
+ SELECT
+ revenue_src_10007.revenue AS txn_revenue
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy
+ , revenue_src_10007.user_id AS user
+ , revenue_src_10007.user_id AS company__user
+ FROM ***************************.fct_revenue revenue_src_10007
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.ds__month
+) subq_3
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql
new file mode 100644
index 0000000000..a44bb5a72b
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_grain_to_date__plan0_optimized.sql
@@ -0,0 +1,12 @@
+-- Read Elements From Semantic Model 'revenue'
+-- Metric Time Dimension 'ds'
+-- Pass Only Elements:
+-- ['txn_revenue', 'ds__month']
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ DATE_TRUNC('month', created_at) AS ds__month
+ , SUM(revenue) AS revenue_mtd
+FROM ***************************.fct_revenue revenue_src_10007
+GROUP BY
+ DATE_TRUNC('month', created_at)
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql
new file mode 100644
index 0000000000..afce151a3d
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0.sql
@@ -0,0 +1,84 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_3.txn_revenue AS trailing_2_months_revenue
+FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_2.txn_revenue) AS txn_revenue
+ FROM (
+ -- Pass Only Elements:
+ -- ['txn_revenue']
+ SELECT
+ subq_1.txn_revenue
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.company__ds__day
+ , subq_0.company__ds__week
+ , subq_0.company__ds__month
+ , subq_0.company__ds__quarter
+ , subq_0.company__ds__year
+ , subq_0.company__ds__extract_year
+ , subq_0.company__ds__extract_quarter
+ , subq_0.company__ds__extract_month
+ , subq_0.company__ds__extract_day
+ , subq_0.company__ds__extract_dow
+ , subq_0.company__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.company__user
+ , subq_0.txn_revenue
+ FROM (
+ -- Read Elements From Semantic Model 'revenue'
+ SELECT
+ revenue_src_10007.revenue AS txn_revenue
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy
+ , revenue_src_10007.user_id AS user
+ , revenue_src_10007.user_id AS company__user
+ FROM ***************************.fct_revenue revenue_src_10007
+ ) subq_0
+ ) subq_1
+ ) subq_2
+) subq_3
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql
new file mode 100644
index 0000000000..30e9e6946d
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_ds__plan0_optimized.sql
@@ -0,0 +1,9 @@
+-- Read Elements From Semantic Model 'revenue'
+-- Metric Time Dimension 'ds'
+-- Pass Only Elements:
+-- ['txn_revenue']
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ SUM(revenue) AS trailing_2_months_revenue
+FROM ***************************.fct_revenue revenue_src_10007
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql
new file mode 100644
index 0000000000..5062fa6a66
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0.sql
@@ -0,0 +1,89 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_3.ds__month
+ , subq_3.txn_revenue AS revenue_all_time
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.ds__month
+ , SUM(subq_2.txn_revenue) AS txn_revenue
+ FROM (
+ -- Pass Only Elements:
+ -- ['txn_revenue', 'ds__month']
+ SELECT
+ subq_1.ds__month
+ , subq_1.txn_revenue
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.company__ds__day
+ , subq_0.company__ds__week
+ , subq_0.company__ds__month
+ , subq_0.company__ds__quarter
+ , subq_0.company__ds__year
+ , subq_0.company__ds__extract_year
+ , subq_0.company__ds__extract_quarter
+ , subq_0.company__ds__extract_month
+ , subq_0.company__ds__extract_day
+ , subq_0.company__ds__extract_dow
+ , subq_0.company__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.company__user
+ , subq_0.txn_revenue
+ FROM (
+ -- Read Elements From Semantic Model 'revenue'
+ SELECT
+ revenue_src_10007.revenue AS txn_revenue
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy
+ , revenue_src_10007.user_id AS user
+ , revenue_src_10007.user_id AS company__user
+ FROM ***************************.fct_revenue revenue_src_10007
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.ds__month
+) subq_3
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql
new file mode 100644
index 0000000000..ccf3a0f545
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window__plan0_optimized.sql
@@ -0,0 +1,12 @@
+-- Read Elements From Semantic Model 'revenue'
+-- Metric Time Dimension 'ds'
+-- Pass Only Elements:
+-- ['txn_revenue', 'ds__month']
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ DATE_TRUNC('month', created_at) AS ds__month
+ , SUM(revenue) AS revenue_all_time
+FROM ***************************.fct_revenue revenue_src_10007
+GROUP BY
+ DATE_TRUNC('month', created_at)
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql
new file mode 100644
index 0000000000..f5cde6f1a4
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0.sql
@@ -0,0 +1,130 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_4.ds__month
+ , subq_4.txn_revenue AS revenue_all_time
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_3.ds__month
+ , SUM(subq_3.txn_revenue) AS txn_revenue
+ FROM (
+ -- Pass Only Elements:
+ -- ['txn_revenue', 'ds__month']
+ SELECT
+ subq_2.ds__month
+ , subq_2.txn_revenue
+ FROM (
+ -- Constrain Time Range to [2000-01-01T00:00:00, 2020-01-01T00:00:00]
+ SELECT
+ subq_1.ds__day
+ , subq_1.ds__week
+ , subq_1.ds__month
+ , subq_1.ds__quarter
+ , subq_1.ds__year
+ , subq_1.ds__extract_year
+ , subq_1.ds__extract_quarter
+ , subq_1.ds__extract_month
+ , subq_1.ds__extract_day
+ , subq_1.ds__extract_dow
+ , subq_1.ds__extract_doy
+ , subq_1.company__ds__day
+ , subq_1.company__ds__week
+ , subq_1.company__ds__month
+ , subq_1.company__ds__quarter
+ , subq_1.company__ds__year
+ , subq_1.company__ds__extract_year
+ , subq_1.company__ds__extract_quarter
+ , subq_1.company__ds__extract_month
+ , subq_1.company__ds__extract_day
+ , subq_1.company__ds__extract_dow
+ , subq_1.company__ds__extract_doy
+ , subq_1.metric_time__day
+ , subq_1.metric_time__week
+ , subq_1.metric_time__month
+ , subq_1.metric_time__quarter
+ , subq_1.metric_time__year
+ , subq_1.metric_time__extract_year
+ , subq_1.metric_time__extract_quarter
+ , subq_1.metric_time__extract_month
+ , subq_1.metric_time__extract_day
+ , subq_1.metric_time__extract_dow
+ , subq_1.metric_time__extract_doy
+ , subq_1.user
+ , subq_1.company__user
+ , subq_1.txn_revenue
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.company__ds__day
+ , subq_0.company__ds__week
+ , subq_0.company__ds__month
+ , subq_0.company__ds__quarter
+ , subq_0.company__ds__year
+ , subq_0.company__ds__extract_year
+ , subq_0.company__ds__extract_quarter
+ , subq_0.company__ds__extract_month
+ , subq_0.company__ds__extract_day
+ , subq_0.company__ds__extract_dow
+ , subq_0.company__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.company__user
+ , subq_0.txn_revenue
+ FROM (
+ -- Read Elements From Semantic Model 'revenue'
+ SELECT
+ revenue_src_10007.revenue AS txn_revenue
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy
+ , revenue_src_10007.user_id AS user
+ , revenue_src_10007.user_id AS company__user
+ FROM ***************************.fct_revenue revenue_src_10007
+ ) subq_0
+ ) subq_1
+ WHERE subq_1.metric_time__day BETWEEN timestamp '2000-01-01' AND timestamp '2020-01-01'
+ ) subq_2
+ ) subq_3
+ GROUP BY
+ subq_3.ds__month
+) subq_4
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql
new file mode 100644
index 0000000000..2553df7dec
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql
@@ -0,0 +1,14 @@
+-- Read Elements From Semantic Model 'revenue'
+-- Metric Time Dimension 'ds'
+-- Constrain Time Range to [2000-01-01T00:00:00, 2020-01-01T00:00:00]
+-- Pass Only Elements:
+-- ['txn_revenue', 'ds__month']
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ DATE_TRUNC('month', created_at) AS ds__month
+ , SUM(revenue) AS revenue_all_time
+FROM ***************************.fct_revenue revenue_src_10007
+WHERE DATE_TRUNC('day', created_at) BETWEEN timestamp '2000-01-01' AND timestamp '2020-01-01'
+GROUP BY
+ DATE_TRUNC('month', created_at)
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql
new file mode 100644
index 0000000000..28bc3ef177
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql
@@ -0,0 +1,335 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_7.metric_time__day
+ , subq_7.bookers AS every_two_days_bookers
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_6.metric_time__day
+ , COUNT(DISTINCT subq_6.bookers) AS bookers
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_5.metric_time__day
+ , subq_5.bookers
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookers', 'metric_time__day']
+ SELECT
+ subq_4.metric_time__day
+ , subq_4.bookers
+ FROM (
+ -- Join Self Over Time Range
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , 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.metric_time__week AS metric_time__week
+ , subq_1.metric_time__month AS metric_time__month
+ , subq_1.metric_time__quarter AS metric_time__quarter
+ , subq_1.metric_time__year AS metric_time__year
+ , subq_1.metric_time__extract_year AS metric_time__extract_year
+ , subq_1.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_1.metric_time__extract_month AS metric_time__extract_month
+ , subq_1.metric_time__extract_day AS metric_time__extract_day
+ , subq_1.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_1.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_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 (
+ -- Date 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ON
+ (
+ subq_1.metric_time__day <= subq_2.metric_time__day
+ ) AND (
+ subq_1.metric_time__day > DATE_ADD('day', -2, subq_2.metric_time__day)
+ )
+ ) subq_4
+ ) subq_5
+ WHERE metric_time__day = '2020-01-03' or metric_time__day = '2020-01-07'
+ ) subq_6
+ GROUP BY
+ subq_6.metric_time__day
+) subq_7
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql
new file mode 100644
index 0000000000..3e52c58c9f
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql
@@ -0,0 +1,26 @@
+-- Constrain Output with WHERE
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , COUNT(DISTINCT bookers) AS every_two_days_bookers
+FROM (
+ -- Join Self Over Time Range
+ -- Pass Only Elements:
+ -- ['bookers', 'metric_time__day']
+ SELECT
+ subq_11.ds AS metric_time__day
+ , bookings_source_src_10001.guest_id AS bookers
+ FROM ***************************.mf_time_spine subq_11
+ INNER JOIN
+ ***************************.fct_bookings bookings_source_src_10001
+ ON
+ (
+ DATE_TRUNC('day', bookings_source_src_10001.ds) <= subq_11.ds
+ ) AND (
+ DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_ADD('day', -2, subq_11.ds)
+ )
+) subq_13
+WHERE metric_time__day = '2020-01-03' or metric_time__day = '2020-01-07'
+GROUP BY
+ metric_time__day
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql
new file mode 100644
index 0000000000..db1370b7a0
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0.sql
@@ -0,0 +1,190 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_8.metric_time__month
+ , subq_8.txn_revenue AS trailing_2_months_revenue
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_7.metric_time__month
+ , SUM(subq_7.txn_revenue) AS txn_revenue
+ FROM (
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
+ SELECT
+ subq_6.metric_time__month
+ , subq_6.txn_revenue
+ FROM (
+ -- Pass Only Elements:
+ -- ['txn_revenue', 'metric_time__month']
+ SELECT
+ subq_5.metric_time__month
+ , subq_5.txn_revenue
+ FROM (
+ -- Join Self Over Time Range
+ SELECT
+ subq_3.metric_time__day AS metric_time__day
+ , subq_2.ds__day AS ds__day
+ , subq_2.ds__week AS ds__week
+ , subq_2.ds__month AS ds__month
+ , subq_2.ds__quarter AS ds__quarter
+ , subq_2.ds__year AS ds__year
+ , subq_2.ds__extract_year AS ds__extract_year
+ , subq_2.ds__extract_quarter AS ds__extract_quarter
+ , subq_2.ds__extract_month AS ds__extract_month
+ , subq_2.ds__extract_day AS ds__extract_day
+ , subq_2.ds__extract_dow AS ds__extract_dow
+ , subq_2.ds__extract_doy AS ds__extract_doy
+ , subq_2.company__ds__day AS company__ds__day
+ , subq_2.company__ds__week AS company__ds__week
+ , subq_2.company__ds__month AS company__ds__month
+ , subq_2.company__ds__quarter AS company__ds__quarter
+ , subq_2.company__ds__year AS company__ds__year
+ , subq_2.company__ds__extract_year AS company__ds__extract_year
+ , subq_2.company__ds__extract_quarter AS company__ds__extract_quarter
+ , subq_2.company__ds__extract_month AS company__ds__extract_month
+ , subq_2.company__ds__extract_day AS company__ds__extract_day
+ , subq_2.company__ds__extract_dow AS company__ds__extract_dow
+ , subq_2.company__ds__extract_doy AS company__ds__extract_doy
+ , subq_2.metric_time__week AS metric_time__week
+ , subq_2.metric_time__month AS metric_time__month
+ , subq_2.metric_time__quarter AS metric_time__quarter
+ , subq_2.metric_time__year AS metric_time__year
+ , subq_2.metric_time__extract_year AS metric_time__extract_year
+ , subq_2.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_2.metric_time__extract_month AS metric_time__extract_month
+ , subq_2.metric_time__extract_day AS metric_time__extract_day
+ , subq_2.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_2.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_2.user AS user
+ , subq_2.company__user AS company__user
+ , subq_2.txn_revenue AS txn_revenue
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_4.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_4
+ WHERE subq_4.ds BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01'
+ ) subq_3
+ INNER JOIN (
+ -- Constrain Time Range to [2019-11-01T00:00:00, 2020-01-01T00:00:00]
+ SELECT
+ subq_1.ds__day
+ , subq_1.ds__week
+ , subq_1.ds__month
+ , subq_1.ds__quarter
+ , subq_1.ds__year
+ , subq_1.ds__extract_year
+ , subq_1.ds__extract_quarter
+ , subq_1.ds__extract_month
+ , subq_1.ds__extract_day
+ , subq_1.ds__extract_dow
+ , subq_1.ds__extract_doy
+ , subq_1.company__ds__day
+ , subq_1.company__ds__week
+ , subq_1.company__ds__month
+ , subq_1.company__ds__quarter
+ , subq_1.company__ds__year
+ , subq_1.company__ds__extract_year
+ , subq_1.company__ds__extract_quarter
+ , subq_1.company__ds__extract_month
+ , subq_1.company__ds__extract_day
+ , subq_1.company__ds__extract_dow
+ , subq_1.company__ds__extract_doy
+ , subq_1.metric_time__day
+ , subq_1.metric_time__week
+ , subq_1.metric_time__month
+ , subq_1.metric_time__quarter
+ , subq_1.metric_time__year
+ , subq_1.metric_time__extract_year
+ , subq_1.metric_time__extract_quarter
+ , subq_1.metric_time__extract_month
+ , subq_1.metric_time__extract_day
+ , subq_1.metric_time__extract_dow
+ , subq_1.metric_time__extract_doy
+ , subq_1.user
+ , subq_1.company__user
+ , subq_1.txn_revenue
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.company__ds__day
+ , subq_0.company__ds__week
+ , subq_0.company__ds__month
+ , subq_0.company__ds__quarter
+ , subq_0.company__ds__year
+ , subq_0.company__ds__extract_year
+ , subq_0.company__ds__extract_quarter
+ , subq_0.company__ds__extract_month
+ , subq_0.company__ds__extract_day
+ , subq_0.company__ds__extract_dow
+ , subq_0.company__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.user
+ , subq_0.company__user
+ , subq_0.txn_revenue
+ FROM (
+ -- Read Elements From Semantic Model 'revenue'
+ SELECT
+ revenue_src_10007.revenue AS txn_revenue
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', revenue_src_10007.created_at) AS company__ds__day
+ , DATE_TRUNC('week', revenue_src_10007.created_at) AS company__ds__week
+ , DATE_TRUNC('month', revenue_src_10007.created_at) AS company__ds__month
+ , DATE_TRUNC('quarter', revenue_src_10007.created_at) AS company__ds__quarter
+ , DATE_TRUNC('year', revenue_src_10007.created_at) AS company__ds__year
+ , EXTRACT(year FROM revenue_src_10007.created_at) AS company__ds__extract_year
+ , EXTRACT(quarter FROM revenue_src_10007.created_at) AS company__ds__extract_quarter
+ , EXTRACT(month FROM revenue_src_10007.created_at) AS company__ds__extract_month
+ , EXTRACT(day FROM revenue_src_10007.created_at) AS company__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM revenue_src_10007.created_at) AS company__ds__extract_dow
+ , EXTRACT(doy FROM revenue_src_10007.created_at) AS company__ds__extract_doy
+ , revenue_src_10007.user_id AS user
+ , revenue_src_10007.user_id AS company__user
+ FROM ***************************.fct_revenue revenue_src_10007
+ ) subq_0
+ ) subq_1
+ WHERE subq_1.metric_time__day BETWEEN timestamp '2019-11-01' AND timestamp '2020-01-01'
+ ) subq_2
+ ON
+ (
+ subq_2.metric_time__day <= subq_3.metric_time__day
+ ) AND (
+ subq_2.metric_time__day > DATE_ADD('month', -2, subq_3.metric_time__day)
+ )
+ ) subq_5
+ ) subq_6
+ WHERE subq_6.metric_time__month BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01'
+ ) subq_7
+ GROUP BY
+ subq_7.metric_time__month
+) subq_8
diff --git a/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql
new file mode 100644
index 0000000000..07569fc878
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_metric_with_time_constraint__plan0_optimized.sql
@@ -0,0 +1,36 @@
+-- Join Self Over Time Range
+-- Pass Only Elements:
+-- ['txn_revenue', 'metric_time__month']
+-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ subq_11.metric_time__month AS metric_time__month
+ , SUM(subq_11.txn_revenue) AS trailing_2_months_revenue
+FROM (
+ -- Date Spine
+ SELECT
+ ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_13
+ WHERE ds BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01'
+) subq_12
+INNER JOIN (
+ -- Read Elements From Semantic Model 'revenue'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2019-11-01T00:00:00, 2020-01-01T00:00:00]
+ SELECT
+ DATE_TRUNC('day', created_at) AS metric_time__day
+ , DATE_TRUNC('month', created_at) AS metric_time__month
+ , revenue AS txn_revenue
+ FROM ***************************.fct_revenue revenue_src_10007
+ WHERE DATE_TRUNC('day', created_at) BETWEEN timestamp '2019-11-01' AND timestamp '2020-01-01'
+) subq_11
+ON
+ (
+ subq_11.metric_time__day <= subq_12.metric_time__day
+ ) AND (
+ subq_11.metric_time__day > DATE_ADD('month', -2, subq_12.metric_time__day)
+ )
+WHERE subq_11.metric_time__month BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01'
+GROUP BY
+ subq_11.metric_time__month
diff --git a/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_cumulative_metric_with_non_adjustable_filter__query_output.txt b/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_cumulative_metric_with_non_adjustable_filter__query_output.txt
new file mode 100644
index 0000000000..a6e99f543d
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_cumulative_metric_with_non_adjustable_filter__query_output.txt
@@ -0,0 +1,3 @@
+ metric_time__day trailing_2_months_revenue
+0 2020-03-15 7000
+1 2020-04-30 7000
diff --git a/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_grain_to_date_cumulative_metric__query_output.txt b/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_grain_to_date_cumulative_metric__query_output.txt
new file mode 100644
index 0000000000..737fe3f4ca
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_grain_to_date_cumulative_metric__query_output.txt
@@ -0,0 +1,5 @@
+ metric_time__day revenue_mtd
+0 2021-01-03 3000
+1 2021-01-04 4000
+2 2021-01-05 4000
+3 2021-01-06 4000
diff --git a/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_multiple_cumulative_metrics__query_output.txt b/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_multiple_cumulative_metrics__query_output.txt
new file mode 100644
index 0000000000..00ddadd8bd
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_multiple_cumulative_metrics__query_output.txt
@@ -0,0 +1,63 @@
+ metric_time__day revenue_all_time trailing_2_months_revenue
+0 2020-03-31 8000 7000
+1 2020-04-01 8000 3000
+2 2020-04-02 12000 7000
+3 2020-04-03 12000 7000
+4 2020-04-04 12000 7000
+5 2020-04-05 12000 7000
+6 2020-04-06 12000 7000
+7 2020-04-07 12000 7000
+8 2020-04-08 12000 7000
+9 2020-04-09 12000 7000
+10 2020-04-10 12000 7000
+11 2020-04-11 12000 7000
+12 2020-04-12 12000 7000
+13 2020-04-13 12000 7000
+14 2020-04-14 12000 7000
+15 2020-04-15 12000 7000
+16 2020-04-16 12000 7000
+17 2020-04-17 12000 7000
+18 2020-04-18 12000 7000
+19 2020-04-19 12000 7000
+20 2020-04-20 12000 7000
+21 2020-04-21 12000 7000
+22 2020-04-22 12000 7000
+23 2020-04-23 12000 7000
+24 2020-04-24 12000 7000
+25 2020-04-25 12000 7000
+26 2020-04-26 12000 7000
+27 2020-04-27 12000 7000
+28 2020-04-28 12000 7000
+29 2020-04-29 12000 7000
+30 2020-04-30 12000 7000
+31 2020-05-01 12000 4000
+32 2020-05-02 12000 4000
+33 2020-05-03 12000 4000
+34 2020-05-04 12000 4000
+35 2020-05-05 12000 4000
+36 2020-05-06 12000 4000
+37 2020-05-07 12000 4000
+38 2020-05-08 12000 4000
+39 2020-05-09 12000 4000
+40 2020-05-10 12000 4000
+41 2020-05-11 12000 4000
+42 2020-05-12 12000 4000
+43 2020-05-13 12000 4000
+44 2020-05-14 12000 4000
+45 2020-05-15 12000 4000
+46 2020-05-16 12000 4000
+47 2020-05-17 12000 4000
+48 2020-05-18 12000 4000
+49 2020-05-19 12000 4000
+50 2020-05-20 12000 4000
+51 2020-05-21 12000 4000
+52 2020-05-22 12000 4000
+53 2020-05-23 12000 4000
+54 2020-05-24 12000 4000
+55 2020-05-25 12000 4000
+56 2020-05-26 12000 4000
+57 2020-05-27 12000 4000
+58 2020-05-28 12000 4000
+59 2020-05-29 12000 4000
+60 2020-05-30 12000 4000
+61 2020-05-31 12000 4000
diff --git a/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_non_additive_cumulative_metric__query_output.txt b/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_non_additive_cumulative_metric__query_output.txt
new file mode 100644
index 0000000000..9875015274
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_non_additive_cumulative_metric__query_output.txt
@@ -0,0 +1,4 @@
+ metric_time__day every_two_days_bookers
+0 2020-01-01 3
+1 2020-01-02 6
+2 2020-01-03 4
diff --git a/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_simple_cumulative_metric__query_output.txt b/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_simple_cumulative_metric__query_output.txt
new file mode 100644
index 0000000000..57564e85eb
--- /dev/null
+++ b/metricflow/test/snapshots/test_cumulative_metrics.py/str/Trino/test_simple_cumulative_metric__query_output.txt
@@ -0,0 +1,91 @@
+ metric_time__day trailing_2_months_revenue
+0 2020-02-01 5000
+1 2020-02-02 5000
+2 2020-02-03 5000
+3 2020-02-04 5000
+4 2020-02-05 5000
+5 2020-02-06 5000
+6 2020-02-07 5000
+7 2020-02-08 5000
+8 2020-02-09 5000
+9 2020-02-10 5000
+10 2020-02-11 5000
+11 2020-02-12 5000
+12 2020-02-13 5000
+13 2020-02-14 5000
+14 2020-02-15 5000
+15 2020-02-16 5000
+16 2020-02-17 5000
+17 2020-02-18 5000
+18 2020-02-19 5000
+19 2020-02-20 5000
+20 2020-02-21 5000
+21 2020-02-22 5000
+22 2020-02-23 5000
+23 2020-02-24 5000
+24 2020-02-25 5000
+25 2020-02-26 5000
+26 2020-02-27 5000
+27 2020-02-28 5000
+28 2020-02-29 5000
+29 2020-03-01 7000
+30 2020-03-02 7000
+31 2020-03-03 7000
+32 2020-03-04 7000
+33 2020-03-05 7000
+34 2020-03-06 7000
+35 2020-03-07 7000
+36 2020-03-08 7000
+37 2020-03-09 7000
+38 2020-03-10 7000
+39 2020-03-11 7000
+40 2020-03-12 7000
+41 2020-03-13 7000
+42 2020-03-14 7000
+43 2020-03-15 7000
+44 2020-03-16 7000
+45 2020-03-17 7000
+46 2020-03-18 7000
+47 2020-03-19 7000
+48 2020-03-20 7000
+49 2020-03-21 7000
+50 2020-03-22 7000
+51 2020-03-23 7000
+52 2020-03-24 7000
+53 2020-03-25 7000
+54 2020-03-26 7000
+55 2020-03-27 7000
+56 2020-03-28 7000
+57 2020-03-29 7000
+58 2020-03-30 7000
+59 2020-03-31 7000
+60 2020-04-01 3000
+61 2020-04-02 7000
+62 2020-04-03 7000
+63 2020-04-04 7000
+64 2020-04-05 7000
+65 2020-04-06 7000
+66 2020-04-07 7000
+67 2020-04-08 7000
+68 2020-04-09 7000
+69 2020-04-10 7000
+70 2020-04-11 7000
+71 2020-04-12 7000
+72 2020-04-13 7000
+73 2020-04-14 7000
+74 2020-04-15 7000
+75 2020-04-16 7000
+76 2020-04-17 7000
+77 2020-04-18 7000
+78 2020-04-19 7000
+79 2020-04-20 7000
+80 2020-04-21 7000
+81 2020-04-22 7000
+82 2020-04-23 7000
+83 2020-04-24 7000
+84 2020-04-25 7000
+85 2020-04-26 7000
+86 2020-04-27 7000
+87 2020-04-28 7000
+88 2020-04-29 7000
+89 2020-04-30 7000
diff --git a/metricflow/test/snapshots/test_data_warehouse_tasks.py/data_warehouse_validation_manifest/Trino/test_build_metric_tasks__query0.sql b/metricflow/test/snapshots/test_data_warehouse_tasks.py/data_warehouse_validation_manifest/Trino/test_build_metric_tasks__query0.sql
new file mode 100644
index 0000000000..a8484a1d11
--- /dev/null
+++ b/metricflow/test/snapshots/test_data_warehouse_tasks.py/data_warehouse_validation_manifest/Trino/test_build_metric_tasks__query0.sql
@@ -0,0 +1,17 @@
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , SUM(count_dogs) AS count_dogs
+FROM (
+ -- Read Elements From Semantic Model 'animals'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['count_dogs', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS count_dogs
+ FROM ***************************.fct_animals animals_src_0
+) subq_2
+GROUP BY
+ metric_time__day
diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml
new file mode 100644
index 0000000000..bdab0b0d91
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_combined_metrics_plan__ep_0.xml
@@ -0,0 +1,89 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_joined_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_joined_plan__ep_0.xml
new file mode 100644
index 0000000000..e224019fce
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_joined_plan__ep_0.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml
new file mode 100644
index 0000000000..c5d17a25a0
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_multihop_joined_plan__ep_0.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_small_combined_metrics_plan__ep_0.xml b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_small_combined_metrics_plan__ep_0.xml
new file mode 100644
index 0000000000..57ca2f3d3c
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_execution.py/ExecutionPlan/Trino/test_small_combined_metrics_plan__ep_0.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0.sql
new file mode 100644
index 0000000000..e0fa9b4f05
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0.sql
@@ -0,0 +1,228 @@
+-- Combine Aggregated Outputs
+SELECT
+ COALESCE(subq_2.is_instant, subq_5.is_instant) AS is_instant
+ , MAX(subq_2.bookings) AS bookings
+ , COALESCE(MAX(subq_5.instant_bookings), 1) AS instant_bookings
+ , COALESCE(MAX(subq_5.bookers), 1) AS bookers
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_1.is_instant
+ , SUM(subq_1.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'is_instant']
+ SELECT
+ subq_0.is_instant
+ , subq_0.bookings
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ GROUP BY
+ subq_1.is_instant
+) subq_2
+FULL OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ subq_4.is_instant
+ , SUM(subq_4.instant_bookings) AS instant_bookings
+ , COUNT(DISTINCT subq_4.bookers) AS bookers
+ FROM (
+ -- Pass Only Elements:
+ -- ['instant_bookings', 'bookers', 'is_instant']
+ SELECT
+ subq_3.is_instant
+ , subq_3.instant_bookings
+ , subq_3.bookers
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_3
+ ) subq_4
+ GROUP BY
+ subq_4.is_instant
+) subq_5
+ON
+ subq_2.is_instant = subq_5.is_instant
+GROUP BY
+ COALESCE(subq_2.is_instant, subq_5.is_instant)
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0_optimized.sql
new file mode 100644
index 0000000000..62340aabcb
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_combine_output_node__plan0_optimized.sql
@@ -0,0 +1,46 @@
+-- Combine Aggregated Outputs
+SELECT
+ COALESCE(subq_8.is_instant, subq_11.is_instant) AS is_instant
+ , MAX(subq_8.bookings) AS bookings
+ , COALESCE(MAX(subq_11.instant_bookings), 1) AS instant_bookings
+ , COALESCE(MAX(subq_11.bookers), 1) AS bookers
+FROM (
+ -- Aggregate Measures
+ SELECT
+ is_instant
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Pass Only Elements:
+ -- ['bookings', 'is_instant']
+ SELECT
+ is_instant
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_7
+ GROUP BY
+ is_instant
+) subq_8
+FULL OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ is_instant
+ , SUM(instant_bookings) AS instant_bookings
+ , COUNT(DISTINCT bookers) AS bookers
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Pass Only Elements:
+ -- ['instant_bookings', 'bookers', 'is_instant']
+ SELECT
+ is_instant
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , guest_id AS bookers
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_10
+ GROUP BY
+ is_instant
+) subq_11
+ON
+ subq_8.is_instant = subq_11.is_instant
+GROUP BY
+ COALESCE(subq_8.is_instant, subq_11.is_instant)
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql
new file mode 100644
index 0000000000..8cd1791e75
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0.sql
@@ -0,0 +1,192 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_5.listing
+ , subq_5.listing__country_latest
+ , subq_5.bookings
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_4.listing
+ , subq_4.listing__country_latest
+ , SUM(subq_4.bookings) AS bookings
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_1.listing AS listing
+ , subq_3.country_latest AS listing__country_latest
+ , subq_1.bookings AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'listing']
+ SELECT
+ subq_0.listing
+ , subq_0.bookings
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['country_latest', 'listing']
+ SELECT
+ subq_2.listing
+ , subq_2.country_latest
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_2
+ ) subq_3
+ ON
+ subq_1.listing = subq_3.listing
+ ) subq_4
+ GROUP BY
+ subq_4.listing
+ , subq_4.listing__country_latest
+) subq_5
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0_optimized.sql
new file mode 100644
index 0000000000..9e5210f489
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node__plan0_optimized.sql
@@ -0,0 +1,23 @@
+-- Join Standard Outputs
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ subq_7.listing AS listing
+ , listings_latest_src_10005.country AS listing__country_latest
+ , SUM(subq_7.bookings) AS bookings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Pass Only Elements:
+ -- ['bookings', 'listing']
+ SELECT
+ listing_id AS listing
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_7
+LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_10005
+ON
+ subq_7.listing = listings_latest_src_10005.listing_id
+GROUP BY
+ subq_7.listing
+ , listings_latest_src_10005.country
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql
new file mode 100644
index 0000000000..a2b37da09b
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql
@@ -0,0 +1,699 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_20.ds__day
+ , subq_20.listing__country_latest
+ , CAST(subq_20.bookings AS DOUBLE) / CAST(NULLIF(subq_20.views, 0) AS DOUBLE) AS bookings_per_view
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_9.ds__day, subq_19.ds__day) AS ds__day
+ , COALESCE(subq_9.listing__country_latest, subq_19.listing__country_latest) AS listing__country_latest
+ , MAX(subq_9.bookings) AS bookings
+ , MAX(subq_19.views) AS views
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_8.ds__day
+ , subq_8.listing__country_latest
+ , subq_8.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_7.ds__day
+ , subq_7.listing__country_latest
+ , SUM(subq_7.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'listing__country_latest', 'ds__day']
+ SELECT
+ subq_6.ds__day
+ , subq_6.listing__country_latest
+ , subq_6.bookings
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_2.ds__day AS ds__day
+ , subq_2.listing AS listing
+ , subq_5.country_latest AS listing__country_latest
+ , subq_2.bookings AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'ds__day', 'listing']
+ SELECT
+ subq_1.ds__day
+ , subq_1.listing
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['country_latest', 'listing']
+ SELECT
+ subq_4.listing
+ , subq_4.country_latest
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_3.ds__day
+ , subq_3.ds__week
+ , subq_3.ds__month
+ , subq_3.ds__quarter
+ , subq_3.ds__year
+ , subq_3.ds__extract_year
+ , subq_3.ds__extract_quarter
+ , subq_3.ds__extract_month
+ , subq_3.ds__extract_day
+ , subq_3.ds__extract_dow
+ , subq_3.ds__extract_doy
+ , subq_3.created_at__day
+ , subq_3.created_at__week
+ , subq_3.created_at__month
+ , subq_3.created_at__quarter
+ , subq_3.created_at__year
+ , subq_3.created_at__extract_year
+ , subq_3.created_at__extract_quarter
+ , subq_3.created_at__extract_month
+ , subq_3.created_at__extract_day
+ , subq_3.created_at__extract_dow
+ , subq_3.created_at__extract_doy
+ , subq_3.listing__ds__day
+ , subq_3.listing__ds__week
+ , subq_3.listing__ds__month
+ , subq_3.listing__ds__quarter
+ , subq_3.listing__ds__year
+ , subq_3.listing__ds__extract_year
+ , subq_3.listing__ds__extract_quarter
+ , subq_3.listing__ds__extract_month
+ , subq_3.listing__ds__extract_day
+ , subq_3.listing__ds__extract_dow
+ , subq_3.listing__ds__extract_doy
+ , subq_3.listing__created_at__day
+ , subq_3.listing__created_at__week
+ , subq_3.listing__created_at__month
+ , subq_3.listing__created_at__quarter
+ , subq_3.listing__created_at__year
+ , subq_3.listing__created_at__extract_year
+ , subq_3.listing__created_at__extract_quarter
+ , subq_3.listing__created_at__extract_month
+ , subq_3.listing__created_at__extract_day
+ , subq_3.listing__created_at__extract_dow
+ , subq_3.listing__created_at__extract_doy
+ , subq_3.ds__day AS metric_time__day
+ , subq_3.ds__week AS metric_time__week
+ , subq_3.ds__month AS metric_time__month
+ , subq_3.ds__quarter AS metric_time__quarter
+ , subq_3.ds__year AS metric_time__year
+ , subq_3.ds__extract_year AS metric_time__extract_year
+ , subq_3.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_3.ds__extract_month AS metric_time__extract_month
+ , subq_3.ds__extract_day AS metric_time__extract_day
+ , subq_3.ds__extract_dow AS metric_time__extract_dow
+ , subq_3.ds__extract_doy AS metric_time__extract_doy
+ , subq_3.listing
+ , subq_3.user
+ , subq_3.listing__user
+ , subq_3.country_latest
+ , subq_3.is_lux_latest
+ , subq_3.capacity_latest
+ , subq_3.listing__country_latest
+ , subq_3.listing__is_lux_latest
+ , subq_3.listing__capacity_latest
+ , subq_3.listings
+ , subq_3.largest_listing
+ , subq_3.smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_3
+ ) subq_4
+ ) subq_5
+ ON
+ subq_2.listing = subq_5.listing
+ ) subq_6
+ ) subq_7
+ GROUP BY
+ subq_7.ds__day
+ , subq_7.listing__country_latest
+ ) subq_8
+ ) subq_9
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_18.ds__day
+ , subq_18.listing__country_latest
+ , subq_18.views
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_17.ds__day
+ , subq_17.listing__country_latest
+ , SUM(subq_17.views) AS views
+ FROM (
+ -- Pass Only Elements:
+ -- ['views', 'listing__country_latest', 'ds__day']
+ SELECT
+ subq_16.ds__day
+ , subq_16.listing__country_latest
+ , subq_16.views
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_12.ds__day AS ds__day
+ , subq_12.listing AS listing
+ , subq_15.country_latest AS listing__country_latest
+ , subq_12.views AS views
+ FROM (
+ -- Pass Only Elements:
+ -- ['views', 'ds__day', 'listing']
+ SELECT
+ subq_11.ds__day
+ , subq_11.listing
+ , subq_11.views
+ 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.view__ds__day
+ , subq_10.view__ds__week
+ , subq_10.view__ds__month
+ , subq_10.view__ds__quarter
+ , subq_10.view__ds__year
+ , subq_10.view__ds__extract_year
+ , subq_10.view__ds__extract_quarter
+ , subq_10.view__ds__extract_month
+ , subq_10.view__ds__extract_day
+ , subq_10.view__ds__extract_dow
+ , subq_10.view__ds__extract_doy
+ , subq_10.view__ds_partitioned__day
+ , subq_10.view__ds_partitioned__week
+ , subq_10.view__ds_partitioned__month
+ , subq_10.view__ds_partitioned__quarter
+ , subq_10.view__ds_partitioned__year
+ , subq_10.view__ds_partitioned__extract_year
+ , subq_10.view__ds_partitioned__extract_quarter
+ , subq_10.view__ds_partitioned__extract_month
+ , subq_10.view__ds_partitioned__extract_day
+ , subq_10.view__ds_partitioned__extract_dow
+ , subq_10.view__ds_partitioned__extract_doy
+ , subq_10.ds__day AS metric_time__day
+ , subq_10.ds__week AS metric_time__week
+ , subq_10.ds__month AS metric_time__month
+ , subq_10.ds__quarter AS metric_time__quarter
+ , subq_10.ds__year AS metric_time__year
+ , subq_10.ds__extract_year AS metric_time__extract_year
+ , subq_10.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_10.ds__extract_month AS metric_time__extract_month
+ , subq_10.ds__extract_day AS metric_time__extract_day
+ , subq_10.ds__extract_dow AS metric_time__extract_dow
+ , subq_10.ds__extract_doy AS metric_time__extract_doy
+ , subq_10.listing
+ , subq_10.user
+ , subq_10.view__listing
+ , subq_10.view__user
+ , subq_10.views
+ FROM (
+ -- Read Elements From Semantic Model 'views_source'
+ SELECT
+ 1 AS views
+ , DATE_TRUNC('day', views_source_src_10010.ds) AS ds__day
+ , DATE_TRUNC('week', views_source_src_10010.ds) AS ds__week
+ , DATE_TRUNC('month', views_source_src_10010.ds) AS ds__month
+ , DATE_TRUNC('quarter', views_source_src_10010.ds) AS ds__quarter
+ , DATE_TRUNC('year', views_source_src_10010.ds) AS ds__year
+ , EXTRACT(year FROM views_source_src_10010.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM views_source_src_10010.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM views_source_src_10010.ds) AS ds__extract_month
+ , EXTRACT(day FROM views_source_src_10010.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM views_source_src_10010.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM views_source_src_10010.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', views_source_src_10010.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', views_source_src_10010.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', views_source_src_10010.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', views_source_src_10010.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', views_source_src_10010.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM views_source_src_10010.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', views_source_src_10010.ds) AS view__ds__day
+ , DATE_TRUNC('week', views_source_src_10010.ds) AS view__ds__week
+ , DATE_TRUNC('month', views_source_src_10010.ds) AS view__ds__month
+ , DATE_TRUNC('quarter', views_source_src_10010.ds) AS view__ds__quarter
+ , DATE_TRUNC('year', views_source_src_10010.ds) AS view__ds__year
+ , EXTRACT(year FROM views_source_src_10010.ds) AS view__ds__extract_year
+ , EXTRACT(quarter FROM views_source_src_10010.ds) AS view__ds__extract_quarter
+ , EXTRACT(month FROM views_source_src_10010.ds) AS view__ds__extract_month
+ , EXTRACT(day FROM views_source_src_10010.ds) AS view__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM views_source_src_10010.ds) AS view__ds__extract_dow
+ , EXTRACT(doy FROM views_source_src_10010.ds) AS view__ds__extract_doy
+ , DATE_TRUNC('day', views_source_src_10010.ds_partitioned) AS view__ds_partitioned__day
+ , DATE_TRUNC('week', views_source_src_10010.ds_partitioned) AS view__ds_partitioned__week
+ , DATE_TRUNC('month', views_source_src_10010.ds_partitioned) AS view__ds_partitioned__month
+ , DATE_TRUNC('quarter', views_source_src_10010.ds_partitioned) AS view__ds_partitioned__quarter
+ , DATE_TRUNC('year', views_source_src_10010.ds_partitioned) AS view__ds_partitioned__year
+ , EXTRACT(year FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_month
+ , EXTRACT(day FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM views_source_src_10010.ds_partitioned) AS view__ds_partitioned__extract_doy
+ , views_source_src_10010.listing_id AS listing
+ , views_source_src_10010.user_id AS user
+ , views_source_src_10010.listing_id AS view__listing
+ , views_source_src_10010.user_id AS view__user
+ FROM ***************************.fct_views views_source_src_10010
+ ) subq_10
+ ) subq_11
+ ) subq_12
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['country_latest', 'listing']
+ SELECT
+ subq_14.listing
+ , subq_14.country_latest
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_13.ds__day
+ , subq_13.ds__week
+ , subq_13.ds__month
+ , subq_13.ds__quarter
+ , subq_13.ds__year
+ , subq_13.ds__extract_year
+ , subq_13.ds__extract_quarter
+ , subq_13.ds__extract_month
+ , subq_13.ds__extract_day
+ , subq_13.ds__extract_dow
+ , subq_13.ds__extract_doy
+ , subq_13.created_at__day
+ , subq_13.created_at__week
+ , subq_13.created_at__month
+ , subq_13.created_at__quarter
+ , subq_13.created_at__year
+ , subq_13.created_at__extract_year
+ , subq_13.created_at__extract_quarter
+ , subq_13.created_at__extract_month
+ , subq_13.created_at__extract_day
+ , subq_13.created_at__extract_dow
+ , subq_13.created_at__extract_doy
+ , subq_13.listing__ds__day
+ , subq_13.listing__ds__week
+ , subq_13.listing__ds__month
+ , subq_13.listing__ds__quarter
+ , subq_13.listing__ds__year
+ , subq_13.listing__ds__extract_year
+ , subq_13.listing__ds__extract_quarter
+ , subq_13.listing__ds__extract_month
+ , subq_13.listing__ds__extract_day
+ , subq_13.listing__ds__extract_dow
+ , subq_13.listing__ds__extract_doy
+ , subq_13.listing__created_at__day
+ , subq_13.listing__created_at__week
+ , subq_13.listing__created_at__month
+ , subq_13.listing__created_at__quarter
+ , subq_13.listing__created_at__year
+ , subq_13.listing__created_at__extract_year
+ , subq_13.listing__created_at__extract_quarter
+ , subq_13.listing__created_at__extract_month
+ , subq_13.listing__created_at__extract_day
+ , subq_13.listing__created_at__extract_dow
+ , subq_13.listing__created_at__extract_doy
+ , subq_13.ds__day AS metric_time__day
+ , subq_13.ds__week AS metric_time__week
+ , subq_13.ds__month AS metric_time__month
+ , subq_13.ds__quarter AS metric_time__quarter
+ , subq_13.ds__year AS metric_time__year
+ , subq_13.ds__extract_year AS metric_time__extract_year
+ , subq_13.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_13.ds__extract_month AS metric_time__extract_month
+ , subq_13.ds__extract_day AS metric_time__extract_day
+ , subq_13.ds__extract_dow AS metric_time__extract_dow
+ , subq_13.ds__extract_doy AS metric_time__extract_doy
+ , subq_13.listing
+ , subq_13.user
+ , subq_13.listing__user
+ , subq_13.country_latest
+ , subq_13.is_lux_latest
+ , subq_13.capacity_latest
+ , subq_13.listing__country_latest
+ , subq_13.listing__is_lux_latest
+ , subq_13.listing__capacity_latest
+ , subq_13.listings
+ , subq_13.largest_listing
+ , subq_13.smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_13
+ ) subq_14
+ ) subq_15
+ ON
+ subq_12.listing = subq_15.listing
+ ) subq_16
+ ) subq_17
+ GROUP BY
+ subq_17.ds__day
+ , subq_17.listing__country_latest
+ ) subq_18
+ ) subq_19
+ ON
+ (
+ subq_9.listing__country_latest = subq_19.listing__country_latest
+ ) AND (
+ subq_9.ds__day = subq_19.ds__day
+ )
+ GROUP BY
+ COALESCE(subq_9.ds__day, subq_19.ds__day)
+ , COALESCE(subq_9.listing__country_latest, subq_19.listing__country_latest)
+) subq_20
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql
new file mode 100644
index 0000000000..ee6adb1fd6
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql
@@ -0,0 +1,80 @@
+-- Compute Metrics via Expressions
+SELECT
+ ds__day
+ , listing__country_latest
+ , CAST(bookings AS DOUBLE) / CAST(NULLIF(views, 0) AS DOUBLE) AS bookings_per_view
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_30.ds__day, subq_40.ds__day) AS ds__day
+ , COALESCE(subq_30.listing__country_latest, subq_40.listing__country_latest) AS listing__country_latest
+ , MAX(subq_30.bookings) AS bookings
+ , MAX(subq_40.views) AS views
+ FROM (
+ -- Join Standard Outputs
+ -- Pass Only Elements:
+ -- ['bookings', 'listing__country_latest', 'ds__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_23.ds__day AS ds__day
+ , listings_latest_src_10005.country AS listing__country_latest
+ , SUM(subq_23.bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'ds__day', 'listing']
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , listing_id AS listing
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_23
+ LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_10005
+ ON
+ subq_23.listing = listings_latest_src_10005.listing_id
+ GROUP BY
+ subq_23.ds__day
+ , listings_latest_src_10005.country
+ ) subq_30
+ FULL OUTER JOIN (
+ -- Join Standard Outputs
+ -- Pass Only Elements:
+ -- ['views', 'listing__country_latest', 'ds__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_33.ds__day AS ds__day
+ , listings_latest_src_10005.country AS listing__country_latest
+ , SUM(subq_33.views) AS views
+ FROM (
+ -- Read Elements From Semantic Model 'views_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['views', 'ds__day', 'listing']
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , listing_id AS listing
+ , 1 AS views
+ FROM ***************************.fct_views views_source_src_10010
+ ) subq_33
+ LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_10005
+ ON
+ subq_33.listing = listings_latest_src_10005.listing_id
+ GROUP BY
+ subq_33.ds__day
+ , listings_latest_src_10005.country
+ ) subq_40
+ ON
+ (
+ subq_30.listing__country_latest = subq_40.listing__country_latest
+ ) AND (
+ subq_30.ds__day = subq_40.ds__day
+ )
+ GROUP BY
+ COALESCE(subq_30.ds__day, subq_40.ds__day)
+ , COALESCE(subq_30.listing__country_latest, subq_40.listing__country_latest)
+) subq_41
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql
new file mode 100644
index 0000000000..d8fa906713
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql
@@ -0,0 +1,195 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_5.listing
+ , subq_5.listing__country_latest
+ , CAST(subq_5.bookings AS DOUBLE) / CAST(NULLIF(subq_5.bookers, 0) AS DOUBLE) AS bookings_per_booker
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_4.listing
+ , subq_4.listing__country_latest
+ , SUM(subq_4.bookings) AS bookings
+ , COUNT(DISTINCT subq_4.bookers) AS bookers
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_1.listing AS listing
+ , subq_3.country_latest AS listing__country_latest
+ , subq_1.bookings AS bookings
+ , subq_1.bookers AS bookers
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'bookers', 'listing']
+ SELECT
+ subq_0.listing
+ , subq_0.bookings
+ , subq_0.bookers
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['country_latest', 'listing']
+ SELECT
+ subq_2.listing
+ , subq_2.country_latest
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_2
+ ) subq_3
+ ON
+ subq_1.listing = subq_3.listing
+ ) subq_4
+ GROUP BY
+ subq_4.listing
+ , subq_4.listing__country_latest
+) subq_5
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql
new file mode 100644
index 0000000000..0bfa1bff7f
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql
@@ -0,0 +1,31 @@
+-- Compute Metrics via Expressions
+SELECT
+ listing
+ , listing__country_latest
+ , CAST(bookings AS DOUBLE) / CAST(NULLIF(bookers, 0) AS DOUBLE) AS bookings_per_booker
+FROM (
+ -- Join Standard Outputs
+ -- Aggregate Measures
+ SELECT
+ subq_7.listing AS listing
+ , listings_latest_src_10005.country AS listing__country_latest
+ , SUM(subq_7.bookings) AS bookings
+ , COUNT(DISTINCT subq_7.bookers) AS bookers
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Pass Only Elements:
+ -- ['bookings', 'bookers', 'listing']
+ SELECT
+ listing_id AS listing
+ , 1 AS bookings
+ , guest_id AS bookers
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_7
+ LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_10005
+ ON
+ subq_7.listing = listings_latest_src_10005.listing_id
+ GROUP BY
+ subq_7.listing
+ , listings_latest_src_10005.country
+) subq_11
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql
new file mode 100644
index 0000000000..22428879cc
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0.sql
@@ -0,0 +1,192 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_5.listing
+ , subq_5.listing__country_latest
+ , booking_value * 0.05 AS booking_fees
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_4.listing
+ , subq_4.listing__country_latest
+ , SUM(subq_4.booking_value) AS booking_value
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_1.listing AS listing
+ , subq_3.country_latest AS listing__country_latest
+ , subq_1.booking_value AS booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_value', 'listing']
+ SELECT
+ subq_0.listing
+ , subq_0.booking_value
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['country_latest', 'listing']
+ SELECT
+ subq_2.listing
+ , subq_2.country_latest
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_2
+ ) subq_3
+ ON
+ subq_1.listing = subq_3.listing
+ ) subq_4
+ GROUP BY
+ subq_4.listing
+ , subq_4.listing__country_latest
+) subq_5
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0_optimized.sql
new file mode 100644
index 0000000000..5a844f2632
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_compute_metrics_node_simple_expr__plan0_optimized.sql
@@ -0,0 +1,21 @@
+-- Compute Metrics via Expressions
+SELECT
+ listing
+ , listing__country_latest
+ , booking_value * 0.05 AS booking_fees
+FROM (
+ -- Join Standard Outputs
+ -- Aggregate Measures
+ SELECT
+ bookings_source_src_10001.listing_id AS listing
+ , listings_latest_src_10005.country AS listing__country_latest
+ , SUM(bookings_source_src_10001.booking_value) AS booking_value
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_10005
+ ON
+ bookings_source_src_10001.listing_id = listings_latest_src_10005.listing_id
+ GROUP BY
+ bookings_source_src_10001.listing_id
+ , listings_latest_src_10005.country
+) subq_11
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql
new file mode 100644
index 0000000000..bbb44ecc25
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0.sql
@@ -0,0 +1,113 @@
+-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+SELECT
+ subq_2.ds__day
+ , subq_2.metric_time__day
+ , subq_2.bookings
+FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_1.ds__day
+ , subq_1.ds__day AS metric_time__day
+ , subq_1.bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'ds__day']
+ SELECT
+ subq_0.ds__day
+ , subq_0.bookings
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+) subq_2
+WHERE subq_2.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql
new file mode 100644
index 0000000000..653f418578
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_constrain_time_range_node__plan0_optimized.sql
@@ -0,0 +1,11 @@
+-- Read Elements From Semantic Model 'bookings_source'
+-- Pass Only Elements:
+-- ['bookings', 'ds__day']
+-- Metric Time Dimension 'ds'
+-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00]
+SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+FROM ***************************.fct_bookings bookings_source_src_10001
+WHERE DATE_TRUNC('day', ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-02'
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0.sql
new file mode 100644
index 0000000000..51a97deab5
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0.sql
@@ -0,0 +1,229 @@
+-- Pass Only Elements:
+-- ['user__home_state_latest']
+SELECT
+ subq_4.user__home_state_latest
+FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_3.ds__day
+ , subq_3.ds__week
+ , subq_3.ds__month
+ , subq_3.ds__quarter
+ , subq_3.ds__year
+ , subq_3.ds__extract_year
+ , subq_3.ds__extract_quarter
+ , subq_3.ds__extract_month
+ , subq_3.ds__extract_day
+ , subq_3.ds__extract_dow
+ , subq_3.ds__extract_doy
+ , subq_3.created_at__day
+ , subq_3.created_at__week
+ , subq_3.created_at__month
+ , subq_3.created_at__quarter
+ , subq_3.created_at__year
+ , subq_3.created_at__extract_year
+ , subq_3.created_at__extract_quarter
+ , subq_3.created_at__extract_month
+ , subq_3.created_at__extract_day
+ , subq_3.created_at__extract_dow
+ , subq_3.created_at__extract_doy
+ , subq_3.listing__ds__day
+ , subq_3.listing__ds__week
+ , subq_3.listing__ds__month
+ , subq_3.listing__ds__quarter
+ , subq_3.listing__ds__year
+ , subq_3.listing__ds__extract_year
+ , subq_3.listing__ds__extract_quarter
+ , subq_3.listing__ds__extract_month
+ , subq_3.listing__ds__extract_day
+ , subq_3.listing__ds__extract_dow
+ , subq_3.listing__ds__extract_doy
+ , subq_3.listing__created_at__day
+ , subq_3.listing__created_at__week
+ , subq_3.listing__created_at__month
+ , subq_3.listing__created_at__quarter
+ , subq_3.listing__created_at__year
+ , subq_3.listing__created_at__extract_year
+ , subq_3.listing__created_at__extract_quarter
+ , subq_3.listing__created_at__extract_month
+ , subq_3.listing__created_at__extract_day
+ , subq_3.listing__created_at__extract_dow
+ , subq_3.listing__created_at__extract_doy
+ , subq_3.listing
+ , subq_3.user
+ , subq_3.listing__user
+ , subq_3.country_latest
+ , subq_3.is_lux_latest
+ , subq_3.capacity_latest
+ , subq_3.listing__country_latest
+ , subq_3.listing__is_lux_latest
+ , subq_3.listing__capacity_latest
+ , subq_3.user__home_state_latest
+ , subq_3.listings
+ , subq_3.largest_listing
+ , subq_3.smallest_listing
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_0.ds__day AS ds__day
+ , subq_0.ds__week AS ds__week
+ , subq_0.ds__month AS ds__month
+ , subq_0.ds__quarter AS ds__quarter
+ , subq_0.ds__year AS ds__year
+ , subq_0.ds__extract_year AS ds__extract_year
+ , subq_0.ds__extract_quarter AS ds__extract_quarter
+ , subq_0.ds__extract_month AS ds__extract_month
+ , subq_0.ds__extract_day AS ds__extract_day
+ , subq_0.ds__extract_dow AS ds__extract_dow
+ , subq_0.ds__extract_doy AS ds__extract_doy
+ , subq_0.created_at__day AS created_at__day
+ , subq_0.created_at__week AS created_at__week
+ , subq_0.created_at__month AS created_at__month
+ , subq_0.created_at__quarter AS created_at__quarter
+ , subq_0.created_at__year AS created_at__year
+ , subq_0.created_at__extract_year AS created_at__extract_year
+ , subq_0.created_at__extract_quarter AS created_at__extract_quarter
+ , subq_0.created_at__extract_month AS created_at__extract_month
+ , subq_0.created_at__extract_day AS created_at__extract_day
+ , subq_0.created_at__extract_dow AS created_at__extract_dow
+ , subq_0.created_at__extract_doy AS created_at__extract_doy
+ , subq_0.listing__ds__day AS listing__ds__day
+ , subq_0.listing__ds__week AS listing__ds__week
+ , subq_0.listing__ds__month AS listing__ds__month
+ , subq_0.listing__ds__quarter AS listing__ds__quarter
+ , subq_0.listing__ds__year AS listing__ds__year
+ , subq_0.listing__ds__extract_year AS listing__ds__extract_year
+ , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter
+ , subq_0.listing__ds__extract_month AS listing__ds__extract_month
+ , subq_0.listing__ds__extract_day AS listing__ds__extract_day
+ , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow
+ , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy
+ , subq_0.listing__created_at__day AS listing__created_at__day
+ , subq_0.listing__created_at__week AS listing__created_at__week
+ , subq_0.listing__created_at__month AS listing__created_at__month
+ , subq_0.listing__created_at__quarter AS listing__created_at__quarter
+ , subq_0.listing__created_at__year AS listing__created_at__year
+ , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year
+ , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter
+ , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month
+ , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day
+ , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow
+ , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy
+ , subq_0.listing AS listing
+ , subq_0.user AS user
+ , subq_0.listing__user AS listing__user
+ , subq_0.country_latest AS country_latest
+ , subq_0.is_lux_latest AS is_lux_latest
+ , subq_0.capacity_latest AS capacity_latest
+ , subq_0.listing__country_latest AS listing__country_latest
+ , subq_0.listing__is_lux_latest AS listing__is_lux_latest
+ , subq_0.listing__capacity_latest AS listing__capacity_latest
+ , subq_2.home_state_latest AS user__home_state_latest
+ , subq_0.listings AS listings
+ , subq_0.largest_listing AS largest_listing
+ , subq_0.smallest_listing AS smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_0
+ FULL OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['home_state_latest', 'user']
+ SELECT
+ subq_1.user
+ , subq_1.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_10009.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_10009.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_10009.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_10009.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_10009.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10009.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10009.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_10009.ds) AS ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10009.ds) AS ds_latest__extract_doy
+ , users_latest_src_10009.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_10009.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_10009.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_10009.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_10009.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_10009.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10009.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10009.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_10009.ds) AS user__ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10009.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_10009.home_state_latest AS user__home_state_latest
+ , users_latest_src_10009.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_10009
+ ) subq_1
+ ) subq_2
+ ON
+ subq_0.user = subq_2.user
+ ) subq_3
+ WHERE listing__country_latest = 'us'
+) subq_4
+GROUP BY
+ subq_4.user__home_state_latest
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0_optimized.sql
new file mode 100644
index 0000000000..bbb933bac0
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimension_with_joined_where_constraint__plan0_optimized.sql
@@ -0,0 +1,19 @@
+-- Constrain Output with WHERE
+-- Pass Only Elements:
+-- ['user__home_state_latest']
+SELECT
+ user__home_state_latest
+FROM (
+ -- Join Standard Outputs
+ SELECT
+ listings_latest_src_10005.country AS listing__country_latest
+ , users_latest_src_10009.home_state_latest AS user__home_state_latest
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ FULL OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_10009
+ ON
+ listings_latest_src_10005.user_id = users_latest_src_10009.user_id
+) subq_8
+WHERE listing__country_latest = 'us'
+GROUP BY
+ user__home_state_latest
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql
new file mode 100644
index 0000000000..77f81a9548
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql
@@ -0,0 +1,169 @@
+-- Pass Only Elements:
+-- ['user__home_state_latest', 'listing__is_lux_latest']
+SELECT
+ subq_3.listing__is_lux_latest
+ , subq_3.user__home_state_latest
+FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_0.ds__day AS ds__day
+ , subq_0.ds__week AS ds__week
+ , subq_0.ds__month AS ds__month
+ , subq_0.ds__quarter AS ds__quarter
+ , subq_0.ds__year AS ds__year
+ , subq_0.ds__extract_year AS ds__extract_year
+ , subq_0.ds__extract_quarter AS ds__extract_quarter
+ , subq_0.ds__extract_month AS ds__extract_month
+ , subq_0.ds__extract_day AS ds__extract_day
+ , subq_0.ds__extract_dow AS ds__extract_dow
+ , subq_0.ds__extract_doy AS ds__extract_doy
+ , subq_0.created_at__day AS created_at__day
+ , subq_0.created_at__week AS created_at__week
+ , subq_0.created_at__month AS created_at__month
+ , subq_0.created_at__quarter AS created_at__quarter
+ , subq_0.created_at__year AS created_at__year
+ , subq_0.created_at__extract_year AS created_at__extract_year
+ , subq_0.created_at__extract_quarter AS created_at__extract_quarter
+ , subq_0.created_at__extract_month AS created_at__extract_month
+ , subq_0.created_at__extract_day AS created_at__extract_day
+ , subq_0.created_at__extract_dow AS created_at__extract_dow
+ , subq_0.created_at__extract_doy AS created_at__extract_doy
+ , subq_0.listing__ds__day AS listing__ds__day
+ , subq_0.listing__ds__week AS listing__ds__week
+ , subq_0.listing__ds__month AS listing__ds__month
+ , subq_0.listing__ds__quarter AS listing__ds__quarter
+ , subq_0.listing__ds__year AS listing__ds__year
+ , subq_0.listing__ds__extract_year AS listing__ds__extract_year
+ , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter
+ , subq_0.listing__ds__extract_month AS listing__ds__extract_month
+ , subq_0.listing__ds__extract_day AS listing__ds__extract_day
+ , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow
+ , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy
+ , subq_0.listing__created_at__day AS listing__created_at__day
+ , subq_0.listing__created_at__week AS listing__created_at__week
+ , subq_0.listing__created_at__month AS listing__created_at__month
+ , subq_0.listing__created_at__quarter AS listing__created_at__quarter
+ , subq_0.listing__created_at__year AS listing__created_at__year
+ , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year
+ , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter
+ , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month
+ , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day
+ , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow
+ , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy
+ , subq_0.listing AS listing
+ , subq_0.user AS user
+ , subq_0.listing__user AS listing__user
+ , subq_0.country_latest AS country_latest
+ , subq_0.is_lux_latest AS is_lux_latest
+ , subq_0.capacity_latest AS capacity_latest
+ , subq_0.listing__country_latest AS listing__country_latest
+ , subq_0.listing__is_lux_latest AS listing__is_lux_latest
+ , subq_0.listing__capacity_latest AS listing__capacity_latest
+ , subq_2.home_state_latest AS user__home_state_latest
+ , subq_0.listings AS listings
+ , subq_0.largest_listing AS largest_listing
+ , subq_0.smallest_listing AS smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_0
+ FULL OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['home_state_latest', 'user']
+ SELECT
+ subq_1.user
+ , subq_1.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_10009.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_10009.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_10009.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_10009.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_10009.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10009.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10009.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_10009.ds) AS ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10009.ds) AS ds_latest__extract_doy
+ , users_latest_src_10009.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_10009.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_10009.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_10009.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_10009.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_10009.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10009.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10009.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_10009.ds) AS user__ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10009.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_10009.home_state_latest AS user__home_state_latest
+ , users_latest_src_10009.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_10009
+ ) subq_1
+ ) subq_2
+ ON
+ subq_0.user = subq_2.user
+) subq_3
+GROUP BY
+ subq_3.listing__is_lux_latest
+ , subq_3.user__home_state_latest
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql
new file mode 100644
index 0000000000..7f093b6070
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql
@@ -0,0 +1,14 @@
+-- Join Standard Outputs
+-- Pass Only Elements:
+-- ['user__home_state_latest', 'listing__is_lux_latest']
+SELECT
+ listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , users_latest_src_10009.home_state_latest AS user__home_state_latest
+FROM ***************************.dim_listings_latest listings_latest_src_10005
+FULL OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_10009
+ON
+ listings_latest_src_10005.user_id = users_latest_src_10009.user_id
+GROUP BY
+ listings_latest_src_10005.is_lux
+ , users_latest_src_10009.home_state_latest
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0.sql
new file mode 100644
index 0000000000..e56a6cb7d8
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0.sql
@@ -0,0 +1,97 @@
+-- Pass Only Elements:
+-- ['bookings']
+SELECT
+ subq_0.bookings
+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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_0
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0_optimized.sql
new file mode 100644
index 0000000000..24beb367f1
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_node__plan0_optimized.sql
@@ -0,0 +1,6 @@
+-- Read Elements From Semantic Model 'bookings_source'
+-- Pass Only Elements:
+-- ['bookings']
+SELECT
+ 1 AS bookings
+FROM ***************************.fct_bookings bookings_source_src_10001
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0.sql
new file mode 100644
index 0000000000..5cae218a31
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0.sql
@@ -0,0 +1,105 @@
+-- Constrain Output with WHERE
+SELECT
+ subq_1.ds__day
+ , subq_1.bookings
+FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'ds__day']
+ SELECT
+ subq_0.ds__day
+ , subq_0.bookings
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+) subq_1
+WHERE booking__ds__day = '2020-01-01'
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0_optimized.sql
new file mode 100644
index 0000000000..98241721ca
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_node__plan0_optimized.sql
@@ -0,0 +1,14 @@
+-- Constrain Output with WHERE
+SELECT
+ ds__day
+ , bookings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Pass Only Elements:
+ -- ['bookings', 'ds__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_3
+WHERE booking__ds__day = '2020-01-01'
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql
new file mode 100644
index 0000000000..8412a752eb
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql
@@ -0,0 +1,234 @@
+-- Join to Time Spine Dataset
+SELECT
+ subq_5.metric_time__day AS metric_time__day
+ , subq_4.listing AS listing
+ , subq_4.booking_fees AS booking_fees
+FROM (
+ -- Date Spine
+ SELECT
+ subq_6.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_6
+ WHERE subq_6.ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01'
+) subq_5
+INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.listing
+ , booking_value * 0.05 AS booking_fees
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.listing
+ , SUM(subq_2.booking_value) AS booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day', 'listing']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.listing
+ , subq_1.booking_value
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ , subq_2.listing
+ ) subq_3
+) subq_4
+ON
+ DATE_TRUNC('month', subq_5.metric_time__day) = subq_4.metric_time__day
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql
new file mode 100644
index 0000000000..e3195ff6ad
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql
@@ -0,0 +1,36 @@
+-- Join to Time Spine Dataset
+SELECT
+ subq_12.metric_time__day AS metric_time__day
+ , subq_11.listing AS listing
+ , subq_11.booking_fees AS booking_fees
+FROM (
+ -- Date Spine
+ SELECT
+ ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_13
+ WHERE ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01'
+) subq_12
+INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , listing
+ , booking_value * 0.05 AS booking_fees
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day', 'listing']
+ -- Aggregate Measures
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , listing_id AS listing
+ , SUM(booking_value) AS booking_value
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ GROUP BY
+ DATE_TRUNC('day', ds)
+ , listing_id
+ ) subq_10
+) subq_11
+ON
+ DATE_TRUNC('month', subq_12.metric_time__day) = subq_11.metric_time__day
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql
new file mode 100644
index 0000000000..520a9c82e5
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0.sql
@@ -0,0 +1,234 @@
+-- Join to Time Spine Dataset
+SELECT
+ subq_5.metric_time__day AS metric_time__day
+ , subq_4.listing AS listing
+ , subq_4.booking_fees AS booking_fees
+FROM (
+ -- Date Spine
+ SELECT
+ subq_6.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_6
+ WHERE subq_6.ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01'
+) subq_5
+INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.listing
+ , booking_value * 0.05 AS booking_fees
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.listing
+ , SUM(subq_2.booking_value) AS booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day', 'listing']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.listing
+ , subq_1.booking_value
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ , subq_2.listing
+ ) subq_3
+) subq_4
+ON
+ DATE_ADD('day', -10, subq_5.metric_time__day) = subq_4.metric_time__day
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql
new file mode 100644
index 0000000000..1a6479ac03
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql
@@ -0,0 +1,36 @@
+-- Join to Time Spine Dataset
+SELECT
+ subq_12.metric_time__day AS metric_time__day
+ , subq_11.listing AS listing
+ , subq_11.booking_fees AS booking_fees
+FROM (
+ -- Date Spine
+ SELECT
+ ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_13
+ WHERE ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01'
+) subq_12
+INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , listing
+ , booking_value * 0.05 AS booking_fees
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day', 'listing']
+ -- Aggregate Measures
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , listing_id AS listing
+ , SUM(booking_value) AS booking_value
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ GROUP BY
+ DATE_TRUNC('day', ds)
+ , listing_id
+ ) subq_10
+) subq_11
+ON
+ DATE_ADD('day', -10, subq_12.metric_time__day) = subq_11.metric_time__day
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql
new file mode 100644
index 0000000000..c6152ec507
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0.sql
@@ -0,0 +1,234 @@
+-- Join to Time Spine Dataset
+SELECT
+ subq_5.metric_time__day AS metric_time__day
+ , subq_4.listing AS listing
+ , subq_4.booking_fees AS booking_fees
+FROM (
+ -- Date Spine
+ SELECT
+ subq_6.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_6
+ WHERE subq_6.ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01'
+) subq_5
+INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.listing
+ , booking_value * 0.05 AS booking_fees
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.listing
+ , SUM(subq_2.booking_value) AS booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day', 'listing']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.listing
+ , subq_1.booking_value
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ , subq_2.listing
+ ) subq_3
+) subq_4
+ON
+ subq_5.metric_time__day = subq_4.metric_time__day
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql
new file mode 100644
index 0000000000..c22c620e3c
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_join_to_time_spine_node_without_offset__plan0_optimized.sql
@@ -0,0 +1,36 @@
+-- Join to Time Spine Dataset
+SELECT
+ subq_12.metric_time__day AS metric_time__day
+ , subq_11.listing AS listing
+ , subq_11.booking_fees AS booking_fees
+FROM (
+ -- Date Spine
+ SELECT
+ ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_13
+ WHERE ds BETWEEN timestamp '2020-01-01' AND timestamp '2021-01-01'
+) subq_12
+INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , listing
+ , booking_value * 0.05 AS booking_fees
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day', 'listing']
+ -- Aggregate Measures
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , listing_id AS listing
+ , SUM(booking_value) AS booking_value
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ GROUP BY
+ DATE_TRUNC('day', ds)
+ , listing_id
+ ) subq_10
+) subq_11
+ON
+ subq_12.metric_time__day = subq_11.metric_time__day
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0.sql
new file mode 100644
index 0000000000..7ac33fd585
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0.sql
@@ -0,0 +1,108 @@
+-- Aggregate Measures
+SELECT
+ SUM(subq_1.bookings) AS bookings
+ , SUM(subq_1.instant_bookings) AS instant_bookings
+ , COUNT(DISTINCT subq_1.bookers) AS bookers
+ , AVG(subq_1.average_booking_value) AS average_booking_value
+FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'instant_bookings', 'average_booking_value', 'bookers']
+ SELECT
+ subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+) subq_1
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0_optimized.sql
new file mode 100644
index 0000000000..2118e57c95
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_measure_aggregation_node__plan0_optimized.sql
@@ -0,0 +1,10 @@
+-- Read Elements From Semantic Model 'bookings_source'
+-- Pass Only Elements:
+-- ['bookings', 'instant_bookings', 'average_booking_value', 'bookers']
+-- Aggregate Measures
+SELECT
+ SUM(1) AS bookings
+ , SUM(CASE WHEN is_instant THEN 1 ELSE 0 END) AS instant_bookings
+ , COUNT(DISTINCT guest_id) AS bookers
+ , AVG(booking_value) AS average_booking_value
+FROM ***************************.fct_bookings bookings_source_src_10001
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql
new file mode 100644
index 0000000000..26d887d309
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0.sql
@@ -0,0 +1,246 @@
+-- Join Standard Outputs
+SELECT
+ subq_1.listing AS listing
+ , subq_3.country_latest AS listing__country_latest
+ , subq_5.country_latest AS listing__country_latest
+ , subq_1.bookings AS bookings
+FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'listing']
+ SELECT
+ subq_0.listing
+ , subq_0.bookings
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+) subq_1
+LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['country_latest', 'listing']
+ SELECT
+ subq_2.listing
+ , subq_2.country_latest
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_2
+) subq_3
+ON
+ subq_1.listing = subq_3.listing
+LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['country_latest', 'listing']
+ SELECT
+ subq_4.listing
+ , subq_4.country_latest
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_4
+) subq_5
+ON
+ subq_1.listing = subq_5.listing
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0_optimized.sql
new file mode 100644
index 0000000000..ddfc1d9706
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_multi_join_node__plan0_optimized.sql
@@ -0,0 +1,37 @@
+-- Join Standard Outputs
+SELECT
+ subq_7.listing AS listing
+ , subq_9.country_latest AS listing__country_latest
+ , subq_11.country_latest AS listing__country_latest
+ , subq_7.bookings AS bookings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Pass Only Elements:
+ -- ['bookings', 'listing']
+ SELECT
+ listing_id AS listing
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_7
+LEFT OUTER JOIN (
+ -- Read Elements From Semantic Model 'listings_latest'
+ -- Pass Only Elements:
+ -- ['country_latest', 'listing']
+ SELECT
+ listing_id AS listing
+ , country AS country_latest
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+) subq_9
+ON
+ subq_7.listing = subq_9.listing
+LEFT OUTER JOIN (
+ -- Read Elements From Semantic Model 'listings_latest'
+ -- Pass Only Elements:
+ -- ['country_latest', 'listing']
+ SELECT
+ listing_id AS listing
+ , country AS country_latest
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+) subq_11
+ON
+ subq_7.listing = subq_11.listing
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0.sql
new file mode 100644
index 0000000000..6abdafb81f
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0.sql
@@ -0,0 +1,124 @@
+-- Order By ['ds__day', 'bookings']
+SELECT
+ subq_3.ds__day
+ , subq_3.is_instant
+ , subq_3.bookings
+FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_2.ds__day
+ , subq_2.is_instant
+ , subq_2.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_1.ds__day
+ , subq_1.is_instant
+ , SUM(subq_1.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'is_instant', 'ds__day']
+ SELECT
+ subq_0.ds__day
+ , subq_0.is_instant
+ , subq_0.bookings
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ GROUP BY
+ subq_1.ds__day
+ , subq_1.is_instant
+ ) subq_2
+) subq_3
+ORDER BY subq_3.ds__day, subq_3.bookings DESC
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0_optimized.sql
new file mode 100644
index 0000000000..b0e38b1d22
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_order_by_node__plan0_optimized.sql
@@ -0,0 +1,21 @@
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+-- Order By ['ds__day', 'bookings']
+SELECT
+ ds__day
+ , is_instant
+ , SUM(bookings) AS bookings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Pass Only Elements:
+ -- ['bookings', 'is_instant', 'ds__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , is_instant
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_5
+GROUP BY
+ ds__day
+ , is_instant
+ORDER BY ds__day, bookings DESC
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0.sql
new file mode 100644
index 0000000000..e2631c06c4
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0.sql
@@ -0,0 +1,106 @@
+-- Join on MIN(ds) and [] grouping by None
+SELECT
+ subq_0.ds__day AS ds__day
+ , subq_0.ds__week AS ds__week
+ , subq_0.ds__month AS ds__month
+ , subq_0.ds__quarter AS ds__quarter
+ , subq_0.ds__year AS ds__year
+ , subq_0.ds__extract_year AS ds__extract_year
+ , subq_0.ds__extract_quarter AS ds__extract_quarter
+ , subq_0.ds__extract_month AS ds__extract_month
+ , subq_0.ds__extract_day AS ds__extract_day
+ , subq_0.ds__extract_dow AS ds__extract_dow
+ , subq_0.ds__extract_doy AS ds__extract_doy
+ , subq_0.account__ds__day AS account__ds__day
+ , subq_0.account__ds__week AS account__ds__week
+ , subq_0.account__ds__month AS account__ds__month
+ , subq_0.account__ds__quarter AS account__ds__quarter
+ , subq_0.account__ds__year AS account__ds__year
+ , subq_0.account__ds__extract_year AS account__ds__extract_year
+ , subq_0.account__ds__extract_quarter AS account__ds__extract_quarter
+ , subq_0.account__ds__extract_month AS account__ds__extract_month
+ , subq_0.account__ds__extract_day AS account__ds__extract_day
+ , subq_0.account__ds__extract_dow AS account__ds__extract_dow
+ , subq_0.account__ds__extract_doy AS account__ds__extract_doy
+ , subq_0.user AS user
+ , subq_0.account__user AS account__user
+ , subq_0.account_type AS account_type
+ , subq_0.account__account_type AS account__account_type
+ , subq_0.account_balance AS account_balance
+ , subq_0.total_account_balance_first_day AS total_account_balance_first_day
+ , subq_0.current_account_balance_by_user AS current_account_balance_by_user
+FROM (
+ -- Read Elements From Semantic Model 'accounts_source'
+ SELECT
+ accounts_source_src_10000.account_balance
+ , accounts_source_src_10000.account_balance AS total_account_balance_first_day
+ , accounts_source_src_10000.account_balance AS current_account_balance_by_user
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy
+ , accounts_source_src_10000.account_type
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy
+ , accounts_source_src_10000.account_type AS account__account_type
+ , accounts_source_src_10000.user_id AS user
+ , accounts_source_src_10000.user_id AS account__user
+ FROM ***************************.fct_accounts accounts_source_src_10000
+) subq_0
+INNER JOIN (
+ -- Filter row on MIN(ds__day)
+ SELECT
+ MIN(subq_1.ds__day) AS ds__day__complete
+ FROM (
+ -- Read Elements From Semantic Model 'accounts_source'
+ SELECT
+ accounts_source_src_10000.account_balance
+ , accounts_source_src_10000.account_balance AS total_account_balance_first_day
+ , accounts_source_src_10000.account_balance AS current_account_balance_by_user
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy
+ , accounts_source_src_10000.account_type
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy
+ , accounts_source_src_10000.account_type AS account__account_type
+ , accounts_source_src_10000.user_id AS user
+ , accounts_source_src_10000.user_id AS account__user
+ FROM ***************************.fct_accounts accounts_source_src_10000
+ ) subq_1
+) subq_2
+ON
+ subq_0.ds__day = subq_2.ds__day__complete
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0_optimized.sql
new file mode 100644
index 0000000000..3bb832607b
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node__plan0_optimized.sql
@@ -0,0 +1,74 @@
+-- Join on MIN(ds) and [] grouping by None
+SELECT
+ subq_3.ds__day AS ds__day
+ , subq_3.ds__week AS ds__week
+ , subq_3.ds__month AS ds__month
+ , subq_3.ds__quarter AS ds__quarter
+ , subq_3.ds__year AS ds__year
+ , subq_3.ds__extract_year AS ds__extract_year
+ , subq_3.ds__extract_quarter AS ds__extract_quarter
+ , subq_3.ds__extract_month AS ds__extract_month
+ , subq_3.ds__extract_day AS ds__extract_day
+ , subq_3.ds__extract_dow AS ds__extract_dow
+ , subq_3.ds__extract_doy AS ds__extract_doy
+ , subq_3.account__ds__day AS account__ds__day
+ , subq_3.account__ds__week AS account__ds__week
+ , subq_3.account__ds__month AS account__ds__month
+ , subq_3.account__ds__quarter AS account__ds__quarter
+ , subq_3.account__ds__year AS account__ds__year
+ , subq_3.account__ds__extract_year AS account__ds__extract_year
+ , subq_3.account__ds__extract_quarter AS account__ds__extract_quarter
+ , subq_3.account__ds__extract_month AS account__ds__extract_month
+ , subq_3.account__ds__extract_day AS account__ds__extract_day
+ , subq_3.account__ds__extract_dow AS account__ds__extract_dow
+ , subq_3.account__ds__extract_doy AS account__ds__extract_doy
+ , subq_3.user AS user
+ , subq_3.account__user AS account__user
+ , subq_3.account_type AS account_type
+ , subq_3.account__account_type AS account__account_type
+ , subq_3.account_balance AS account_balance
+ , subq_3.total_account_balance_first_day AS total_account_balance_first_day
+ , subq_3.current_account_balance_by_user AS current_account_balance_by_user
+FROM (
+ -- Read Elements From Semantic Model 'accounts_source'
+ SELECT
+ account_balance
+ , account_balance AS total_account_balance_first_day
+ , account_balance AS current_account_balance_by_user
+ , DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('week', ds) AS ds__week
+ , DATE_TRUNC('month', ds) AS ds__month
+ , DATE_TRUNC('quarter', ds) AS ds__quarter
+ , DATE_TRUNC('year', ds) AS ds__year
+ , EXTRACT(year FROM ds) AS ds__extract_year
+ , EXTRACT(quarter FROM ds) AS ds__extract_quarter
+ , EXTRACT(month FROM ds) AS ds__extract_month
+ , EXTRACT(day FROM ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow
+ , EXTRACT(doy FROM ds) AS ds__extract_doy
+ , account_type
+ , DATE_TRUNC('day', ds) AS account__ds__day
+ , DATE_TRUNC('week', ds) AS account__ds__week
+ , DATE_TRUNC('month', ds) AS account__ds__month
+ , DATE_TRUNC('quarter', ds) AS account__ds__quarter
+ , DATE_TRUNC('year', ds) AS account__ds__year
+ , EXTRACT(year FROM ds) AS account__ds__extract_year
+ , EXTRACT(quarter FROM ds) AS account__ds__extract_quarter
+ , EXTRACT(month FROM ds) AS account__ds__extract_month
+ , EXTRACT(day FROM ds) AS account__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS account__ds__extract_dow
+ , EXTRACT(doy FROM ds) AS account__ds__extract_doy
+ , account_type AS account__account_type
+ , user_id AS user
+ , user_id AS account__user
+ FROM ***************************.fct_accounts accounts_source_src_10000
+) subq_3
+INNER JOIN (
+ -- Read Elements From Semantic Model 'accounts_source'
+ -- Filter row on MIN(ds__day)
+ SELECT
+ MIN(DATE_TRUNC('day', ds)) AS ds__day__complete
+ FROM ***************************.fct_accounts accounts_source_src_10000
+) subq_5
+ON
+ subq_3.ds__day = subq_5.ds__day__complete
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0.sql
new file mode 100644
index 0000000000..1573868cd0
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0.sql
@@ -0,0 +1,113 @@
+-- Join on MAX(ds) and ['user'] grouping by None
+SELECT
+ subq_0.ds__day AS ds__day
+ , subq_0.ds__week AS ds__week
+ , subq_0.ds__month AS ds__month
+ , subq_0.ds__quarter AS ds__quarter
+ , subq_0.ds__year AS ds__year
+ , subq_0.ds__extract_year AS ds__extract_year
+ , subq_0.ds__extract_quarter AS ds__extract_quarter
+ , subq_0.ds__extract_month AS ds__extract_month
+ , subq_0.ds__extract_day AS ds__extract_day
+ , subq_0.ds__extract_dow AS ds__extract_dow
+ , subq_0.ds__extract_doy AS ds__extract_doy
+ , subq_0.account__ds__day AS account__ds__day
+ , subq_0.account__ds__week AS account__ds__week
+ , subq_0.account__ds__month AS account__ds__month
+ , subq_0.account__ds__quarter AS account__ds__quarter
+ , subq_0.account__ds__year AS account__ds__year
+ , subq_0.account__ds__extract_year AS account__ds__extract_year
+ , subq_0.account__ds__extract_quarter AS account__ds__extract_quarter
+ , subq_0.account__ds__extract_month AS account__ds__extract_month
+ , subq_0.account__ds__extract_day AS account__ds__extract_day
+ , subq_0.account__ds__extract_dow AS account__ds__extract_dow
+ , subq_0.account__ds__extract_doy AS account__ds__extract_doy
+ , subq_0.user AS user
+ , subq_0.account__user AS account__user
+ , subq_0.account_type AS account_type
+ , subq_0.account__account_type AS account__account_type
+ , subq_0.account_balance AS account_balance
+ , subq_0.total_account_balance_first_day AS total_account_balance_first_day
+ , subq_0.current_account_balance_by_user AS current_account_balance_by_user
+FROM (
+ -- Read Elements From Semantic Model 'accounts_source'
+ SELECT
+ accounts_source_src_10000.account_balance
+ , accounts_source_src_10000.account_balance AS total_account_balance_first_day
+ , accounts_source_src_10000.account_balance AS current_account_balance_by_user
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy
+ , accounts_source_src_10000.account_type
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy
+ , accounts_source_src_10000.account_type AS account__account_type
+ , accounts_source_src_10000.user_id AS user
+ , accounts_source_src_10000.user_id AS account__user
+ FROM ***************************.fct_accounts accounts_source_src_10000
+) subq_0
+INNER JOIN (
+ -- Filter row on MAX(ds__day)
+ SELECT
+ subq_1.user
+ , MAX(subq_1.ds__day) AS ds__day__complete
+ FROM (
+ -- Read Elements From Semantic Model 'accounts_source'
+ SELECT
+ accounts_source_src_10000.account_balance
+ , accounts_source_src_10000.account_balance AS total_account_balance_first_day
+ , accounts_source_src_10000.account_balance AS current_account_balance_by_user
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy
+ , accounts_source_src_10000.account_type
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy
+ , accounts_source_src_10000.account_type AS account__account_type
+ , accounts_source_src_10000.user_id AS user
+ , accounts_source_src_10000.user_id AS account__user
+ FROM ***************************.fct_accounts accounts_source_src_10000
+ ) subq_1
+ GROUP BY
+ subq_1.user
+) subq_2
+ON
+ (
+ subq_0.ds__day = subq_2.ds__day__complete
+ ) AND (
+ subq_0.user = subq_2.user
+ )
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0_optimized.sql
new file mode 100644
index 0000000000..0fe5d6b65d
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_grouping__plan0_optimized.sql
@@ -0,0 +1,81 @@
+-- Join on MAX(ds) and ['user'] grouping by None
+SELECT
+ subq_3.ds__day AS ds__day
+ , subq_3.ds__week AS ds__week
+ , subq_3.ds__month AS ds__month
+ , subq_3.ds__quarter AS ds__quarter
+ , subq_3.ds__year AS ds__year
+ , subq_3.ds__extract_year AS ds__extract_year
+ , subq_3.ds__extract_quarter AS ds__extract_quarter
+ , subq_3.ds__extract_month AS ds__extract_month
+ , subq_3.ds__extract_day AS ds__extract_day
+ , subq_3.ds__extract_dow AS ds__extract_dow
+ , subq_3.ds__extract_doy AS ds__extract_doy
+ , subq_3.account__ds__day AS account__ds__day
+ , subq_3.account__ds__week AS account__ds__week
+ , subq_3.account__ds__month AS account__ds__month
+ , subq_3.account__ds__quarter AS account__ds__quarter
+ , subq_3.account__ds__year AS account__ds__year
+ , subq_3.account__ds__extract_year AS account__ds__extract_year
+ , subq_3.account__ds__extract_quarter AS account__ds__extract_quarter
+ , subq_3.account__ds__extract_month AS account__ds__extract_month
+ , subq_3.account__ds__extract_day AS account__ds__extract_day
+ , subq_3.account__ds__extract_dow AS account__ds__extract_dow
+ , subq_3.account__ds__extract_doy AS account__ds__extract_doy
+ , subq_3.user AS user
+ , subq_3.account__user AS account__user
+ , subq_3.account_type AS account_type
+ , subq_3.account__account_type AS account__account_type
+ , subq_3.account_balance AS account_balance
+ , subq_3.total_account_balance_first_day AS total_account_balance_first_day
+ , subq_3.current_account_balance_by_user AS current_account_balance_by_user
+FROM (
+ -- Read Elements From Semantic Model 'accounts_source'
+ SELECT
+ account_balance
+ , account_balance AS total_account_balance_first_day
+ , account_balance AS current_account_balance_by_user
+ , DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('week', ds) AS ds__week
+ , DATE_TRUNC('month', ds) AS ds__month
+ , DATE_TRUNC('quarter', ds) AS ds__quarter
+ , DATE_TRUNC('year', ds) AS ds__year
+ , EXTRACT(year FROM ds) AS ds__extract_year
+ , EXTRACT(quarter FROM ds) AS ds__extract_quarter
+ , EXTRACT(month FROM ds) AS ds__extract_month
+ , EXTRACT(day FROM ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow
+ , EXTRACT(doy FROM ds) AS ds__extract_doy
+ , account_type
+ , DATE_TRUNC('day', ds) AS account__ds__day
+ , DATE_TRUNC('week', ds) AS account__ds__week
+ , DATE_TRUNC('month', ds) AS account__ds__month
+ , DATE_TRUNC('quarter', ds) AS account__ds__quarter
+ , DATE_TRUNC('year', ds) AS account__ds__year
+ , EXTRACT(year FROM ds) AS account__ds__extract_year
+ , EXTRACT(quarter FROM ds) AS account__ds__extract_quarter
+ , EXTRACT(month FROM ds) AS account__ds__extract_month
+ , EXTRACT(day FROM ds) AS account__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS account__ds__extract_dow
+ , EXTRACT(doy FROM ds) AS account__ds__extract_doy
+ , account_type AS account__account_type
+ , user_id AS user
+ , user_id AS account__user
+ FROM ***************************.fct_accounts accounts_source_src_10000
+) subq_3
+INNER JOIN (
+ -- Read Elements From Semantic Model 'accounts_source'
+ -- Filter row on MAX(ds__day)
+ SELECT
+ user_id AS user
+ , MAX(DATE_TRUNC('day', ds)) AS ds__day__complete
+ FROM ***************************.fct_accounts accounts_source_src_10000
+ GROUP BY
+ user_id
+) subq_5
+ON
+ (
+ subq_3.ds__day = subq_5.ds__day__complete
+ ) AND (
+ subq_3.user = subq_5.user
+ )
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0.sql
new file mode 100644
index 0000000000..4cd48b4c62
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0.sql
@@ -0,0 +1,109 @@
+-- Join on MIN(ds) and [] grouping by ds
+SELECT
+ subq_0.ds__day AS ds__day
+ , subq_0.ds__week AS ds__week
+ , subq_0.ds__month AS ds__month
+ , subq_0.ds__quarter AS ds__quarter
+ , subq_0.ds__year AS ds__year
+ , subq_0.ds__extract_year AS ds__extract_year
+ , subq_0.ds__extract_quarter AS ds__extract_quarter
+ , subq_0.ds__extract_month AS ds__extract_month
+ , subq_0.ds__extract_day AS ds__extract_day
+ , subq_0.ds__extract_dow AS ds__extract_dow
+ , subq_0.ds__extract_doy AS ds__extract_doy
+ , subq_0.account__ds__day AS account__ds__day
+ , subq_0.account__ds__week AS account__ds__week
+ , subq_0.account__ds__month AS account__ds__month
+ , subq_0.account__ds__quarter AS account__ds__quarter
+ , subq_0.account__ds__year AS account__ds__year
+ , subq_0.account__ds__extract_year AS account__ds__extract_year
+ , subq_0.account__ds__extract_quarter AS account__ds__extract_quarter
+ , subq_0.account__ds__extract_month AS account__ds__extract_month
+ , subq_0.account__ds__extract_day AS account__ds__extract_day
+ , subq_0.account__ds__extract_dow AS account__ds__extract_dow
+ , subq_0.account__ds__extract_doy AS account__ds__extract_doy
+ , subq_0.user AS user
+ , subq_0.account__user AS account__user
+ , subq_0.account_type AS account_type
+ , subq_0.account__account_type AS account__account_type
+ , subq_0.account_balance AS account_balance
+ , subq_0.total_account_balance_first_day AS total_account_balance_first_day
+ , subq_0.current_account_balance_by_user AS current_account_balance_by_user
+FROM (
+ -- Read Elements From Semantic Model 'accounts_source'
+ SELECT
+ accounts_source_src_10000.account_balance
+ , accounts_source_src_10000.account_balance AS total_account_balance_first_day
+ , accounts_source_src_10000.account_balance AS current_account_balance_by_user
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy
+ , accounts_source_src_10000.account_type
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy
+ , accounts_source_src_10000.account_type AS account__account_type
+ , accounts_source_src_10000.user_id AS user
+ , accounts_source_src_10000.user_id AS account__user
+ FROM ***************************.fct_accounts accounts_source_src_10000
+) subq_0
+INNER JOIN (
+ -- Filter row on MIN(ds__day)
+ SELECT
+ subq_1.ds__week
+ , MIN(subq_1.ds__day) AS ds__day__complete
+ FROM (
+ -- Read Elements From Semantic Model 'accounts_source'
+ SELECT
+ accounts_source_src_10000.account_balance
+ , accounts_source_src_10000.account_balance AS total_account_balance_first_day
+ , accounts_source_src_10000.account_balance AS current_account_balance_by_user
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS ds__extract_doy
+ , accounts_source_src_10000.account_type
+ , DATE_TRUNC('day', accounts_source_src_10000.ds) AS account__ds__day
+ , DATE_TRUNC('week', accounts_source_src_10000.ds) AS account__ds__week
+ , DATE_TRUNC('month', accounts_source_src_10000.ds) AS account__ds__month
+ , DATE_TRUNC('quarter', accounts_source_src_10000.ds) AS account__ds__quarter
+ , DATE_TRUNC('year', accounts_source_src_10000.ds) AS account__ds__year
+ , EXTRACT(year FROM accounts_source_src_10000.ds) AS account__ds__extract_year
+ , EXTRACT(quarter FROM accounts_source_src_10000.ds) AS account__ds__extract_quarter
+ , EXTRACT(month FROM accounts_source_src_10000.ds) AS account__ds__extract_month
+ , EXTRACT(day FROM accounts_source_src_10000.ds) AS account__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_10000.ds) AS account__ds__extract_dow
+ , EXTRACT(doy FROM accounts_source_src_10000.ds) AS account__ds__extract_doy
+ , accounts_source_src_10000.account_type AS account__account_type
+ , accounts_source_src_10000.user_id AS user
+ , accounts_source_src_10000.user_id AS account__user
+ FROM ***************************.fct_accounts accounts_source_src_10000
+ ) subq_1
+ GROUP BY
+ subq_1.ds__week
+) subq_2
+ON
+ subq_0.ds__day = subq_2.ds__day__complete
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0_optimized.sql
new file mode 100644
index 0000000000..2b23979547
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_semi_additive_join_node_with_queried_group_by__plan0_optimized.sql
@@ -0,0 +1,77 @@
+-- Join on MIN(ds) and [] grouping by ds
+SELECT
+ subq_3.ds__day AS ds__day
+ , subq_3.ds__week AS ds__week
+ , subq_3.ds__month AS ds__month
+ , subq_3.ds__quarter AS ds__quarter
+ , subq_3.ds__year AS ds__year
+ , subq_3.ds__extract_year AS ds__extract_year
+ , subq_3.ds__extract_quarter AS ds__extract_quarter
+ , subq_3.ds__extract_month AS ds__extract_month
+ , subq_3.ds__extract_day AS ds__extract_day
+ , subq_3.ds__extract_dow AS ds__extract_dow
+ , subq_3.ds__extract_doy AS ds__extract_doy
+ , subq_3.account__ds__day AS account__ds__day
+ , subq_3.account__ds__week AS account__ds__week
+ , subq_3.account__ds__month AS account__ds__month
+ , subq_3.account__ds__quarter AS account__ds__quarter
+ , subq_3.account__ds__year AS account__ds__year
+ , subq_3.account__ds__extract_year AS account__ds__extract_year
+ , subq_3.account__ds__extract_quarter AS account__ds__extract_quarter
+ , subq_3.account__ds__extract_month AS account__ds__extract_month
+ , subq_3.account__ds__extract_day AS account__ds__extract_day
+ , subq_3.account__ds__extract_dow AS account__ds__extract_dow
+ , subq_3.account__ds__extract_doy AS account__ds__extract_doy
+ , subq_3.user AS user
+ , subq_3.account__user AS account__user
+ , subq_3.account_type AS account_type
+ , subq_3.account__account_type AS account__account_type
+ , subq_3.account_balance AS account_balance
+ , subq_3.total_account_balance_first_day AS total_account_balance_first_day
+ , subq_3.current_account_balance_by_user AS current_account_balance_by_user
+FROM (
+ -- Read Elements From Semantic Model 'accounts_source'
+ SELECT
+ account_balance
+ , account_balance AS total_account_balance_first_day
+ , account_balance AS current_account_balance_by_user
+ , DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('week', ds) AS ds__week
+ , DATE_TRUNC('month', ds) AS ds__month
+ , DATE_TRUNC('quarter', ds) AS ds__quarter
+ , DATE_TRUNC('year', ds) AS ds__year
+ , EXTRACT(year FROM ds) AS ds__extract_year
+ , EXTRACT(quarter FROM ds) AS ds__extract_quarter
+ , EXTRACT(month FROM ds) AS ds__extract_month
+ , EXTRACT(day FROM ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow
+ , EXTRACT(doy FROM ds) AS ds__extract_doy
+ , account_type
+ , DATE_TRUNC('day', ds) AS account__ds__day
+ , DATE_TRUNC('week', ds) AS account__ds__week
+ , DATE_TRUNC('month', ds) AS account__ds__month
+ , DATE_TRUNC('quarter', ds) AS account__ds__quarter
+ , DATE_TRUNC('year', ds) AS account__ds__year
+ , EXTRACT(year FROM ds) AS account__ds__extract_year
+ , EXTRACT(quarter FROM ds) AS account__ds__extract_quarter
+ , EXTRACT(month FROM ds) AS account__ds__extract_month
+ , EXTRACT(day FROM ds) AS account__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS account__ds__extract_dow
+ , EXTRACT(doy FROM ds) AS account__ds__extract_doy
+ , account_type AS account__account_type
+ , user_id AS user
+ , user_id AS account__user
+ FROM ***************************.fct_accounts accounts_source_src_10000
+) subq_3
+INNER JOIN (
+ -- Read Elements From Semantic Model 'accounts_source'
+ -- Filter row on MIN(ds__day)
+ SELECT
+ DATE_TRUNC('week', ds) AS ds__week
+ , MIN(DATE_TRUNC('day', ds)) AS ds__day__complete
+ FROM ***************************.fct_accounts accounts_source_src_10000
+ GROUP BY
+ DATE_TRUNC('week', ds)
+) subq_5
+ON
+ subq_3.ds__day = subq_5.ds__day__complete
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql
new file mode 100644
index 0000000000..9d596e7b4b
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0.sql
@@ -0,0 +1,174 @@
+-- Join Standard Outputs
+SELECT
+ subq_1.listing AS listing
+ , subq_1.bookings AS bookings
+FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'listing']
+ SELECT
+ subq_0.listing
+ , subq_0.bookings
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+) subq_1
+LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['listing__country_latest', 'listing']
+ SELECT
+ subq_2.listing
+ , subq_2.listing__country_latest
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_2
+) subq_3
+ON
+ subq_1.listing = subq_3.listing
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0_optimized.sql
new file mode 100644
index 0000000000..9202940446
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_single_join_node__plan0_optimized.sql
@@ -0,0 +1,17 @@
+-- Join Standard Outputs
+SELECT
+ subq_5.listing AS listing
+ , subq_5.bookings AS bookings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Pass Only Elements:
+ -- ['bookings', 'listing']
+ SELECT
+ listing_id AS listing
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_5
+LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_10005
+ON
+ subq_5.listing = listings_latest_src_10005.listing_id
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0.sql
new file mode 100644
index 0000000000..d04bcf5afc
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0.sql
@@ -0,0 +1,91 @@
+-- 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+FROM ***************************.fct_bookings bookings_source_src_10001
diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0_optimized.sql b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0_optimized.sql
new file mode 100644
index 0000000000..433a78e339
--- /dev/null
+++ b/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Trino/test_source_node__plan0_optimized.sql
@@ -0,0 +1,91 @@
+-- Read Elements From Semantic Model 'bookings_source'
+SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , booking_value
+ , booking_value AS max_booking_value
+ , booking_value AS min_booking_value
+ , guest_id AS bookers
+ , booking_value AS average_booking_value
+ , booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , booking_value AS median_booking_value
+ , booking_value AS booking_value_p99
+ , booking_value AS discrete_booking_value_p99
+ , booking_value AS approximate_continuous_booking_value_p99
+ , booking_value AS approximate_discrete_booking_value_p99
+ , is_instant
+ , DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('week', ds) AS ds__week
+ , DATE_TRUNC('month', ds) AS ds__month
+ , DATE_TRUNC('quarter', ds) AS ds__quarter
+ , DATE_TRUNC('year', ds) AS ds__year
+ , EXTRACT(year FROM ds) AS ds__extract_year
+ , EXTRACT(quarter FROM ds) AS ds__extract_quarter
+ , EXTRACT(month FROM ds) AS ds__extract_month
+ , EXTRACT(day FROM ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow
+ , EXTRACT(doy FROM ds) AS ds__extract_doy
+ , DATE_TRUNC('day', ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', paid_at) AS paid_at__day
+ , DATE_TRUNC('week', paid_at) AS paid_at__week
+ , DATE_TRUNC('month', paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', paid_at) AS paid_at__year
+ , EXTRACT(year FROM paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM paid_at) AS paid_at__extract_doy
+ , is_instant AS booking__is_instant
+ , DATE_TRUNC('day', ds) AS booking__ds__day
+ , DATE_TRUNC('week', ds) AS booking__ds__week
+ , DATE_TRUNC('month', ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', ds) AS booking__ds__year
+ , EXTRACT(year FROM ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM paid_at) AS booking__paid_at__extract_doy
+ , listing_id AS listing
+ , guest_id AS guest
+ , host_id AS host
+ , listing_id AS booking__listing
+ , guest_id AS booking__guest
+ , host_id AS booking__host
+FROM ***************************.fct_bookings bookings_source_src_10001
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
new file mode 100644
index 0000000000..f60fe55ef8
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0.sql
@@ -0,0 +1,442 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_11.metric_time__day
+ , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago
+FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_10.metric_time__day
+ , subq_10.bookers AS every_2_days_bookers_2_days_ago
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_9.metric_time__day
+ , COUNT(DISTINCT subq_9.bookers) AS bookers
+ FROM (
+ -- Constrain Time Range to [2019-12-19T00:00:00, 2020-01-02T00:00:00]
+ SELECT
+ subq_8.metric_time__day
+ , subq_8.bookers
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookers', 'metric_time__day']
+ SELECT
+ subq_7.metric_time__day
+ , subq_7.bookers
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_5.metric_time__day AS metric_time__day
+ , subq_4.ds__day AS ds__day
+ , subq_4.ds__week AS ds__week
+ , subq_4.ds__month AS ds__month
+ , subq_4.ds__quarter AS ds__quarter
+ , subq_4.ds__year AS ds__year
+ , subq_4.ds__extract_year AS ds__extract_year
+ , subq_4.ds__extract_quarter AS ds__extract_quarter
+ , subq_4.ds__extract_month AS ds__extract_month
+ , subq_4.ds__extract_day AS ds__extract_day
+ , subq_4.ds__extract_dow AS ds__extract_dow
+ , subq_4.ds__extract_doy AS ds__extract_doy
+ , subq_4.ds_partitioned__day AS ds_partitioned__day
+ , subq_4.ds_partitioned__week AS ds_partitioned__week
+ , subq_4.ds_partitioned__month AS ds_partitioned__month
+ , subq_4.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_4.ds_partitioned__year AS ds_partitioned__year
+ , subq_4.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_4.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_4.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_4.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_4.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_4.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_4.paid_at__day AS paid_at__day
+ , subq_4.paid_at__week AS paid_at__week
+ , subq_4.paid_at__month AS paid_at__month
+ , subq_4.paid_at__quarter AS paid_at__quarter
+ , subq_4.paid_at__year AS paid_at__year
+ , subq_4.paid_at__extract_year AS paid_at__extract_year
+ , subq_4.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_4.paid_at__extract_month AS paid_at__extract_month
+ , subq_4.paid_at__extract_day AS paid_at__extract_day
+ , subq_4.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_4.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_4.booking__ds__day AS booking__ds__day
+ , subq_4.booking__ds__week AS booking__ds__week
+ , subq_4.booking__ds__month AS booking__ds__month
+ , subq_4.booking__ds__quarter AS booking__ds__quarter
+ , subq_4.booking__ds__year AS booking__ds__year
+ , subq_4.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_4.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_4.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_4.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_4.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_4.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_4.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_4.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_4.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_4.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_4.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_4.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_4.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_4.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_4.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_4.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_4.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_4.booking__paid_at__day AS booking__paid_at__day
+ , subq_4.booking__paid_at__week AS booking__paid_at__week
+ , subq_4.booking__paid_at__month AS booking__paid_at__month
+ , subq_4.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_4.booking__paid_at__year AS booking__paid_at__year
+ , subq_4.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_4.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_4.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_4.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_4.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_4.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_4.listing AS listing
+ , subq_4.guest AS guest
+ , subq_4.host AS host
+ , subq_4.booking__listing AS booking__listing
+ , subq_4.booking__guest AS booking__guest
+ , subq_4.booking__host AS booking__host
+ , subq_4.is_instant AS is_instant
+ , subq_4.booking__is_instant AS booking__is_instant
+ , subq_4.bookings AS bookings
+ , subq_4.instant_bookings AS instant_bookings
+ , subq_4.booking_value AS booking_value
+ , subq_4.max_booking_value AS max_booking_value
+ , subq_4.min_booking_value AS min_booking_value
+ , subq_4.bookers AS bookers
+ , subq_4.average_booking_value AS average_booking_value
+ , subq_4.referred_bookings AS referred_bookings
+ , subq_4.median_booking_value AS median_booking_value
+ , subq_4.booking_value_p99 AS booking_value_p99
+ , subq_4.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_4.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_4.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_6.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_6
+ WHERE subq_6.ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02'
+ ) subq_5
+ INNER JOIN (
+ -- Join Self Over Time Range
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , 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.metric_time__week AS metric_time__week
+ , subq_1.metric_time__month AS metric_time__month
+ , subq_1.metric_time__quarter AS metric_time__quarter
+ , subq_1.metric_time__year AS metric_time__year
+ , subq_1.metric_time__extract_year AS metric_time__extract_year
+ , subq_1.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_1.metric_time__extract_month AS metric_time__extract_month
+ , subq_1.metric_time__extract_day AS metric_time__extract_day
+ , subq_1.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_1.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_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 (
+ -- Date 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ON
+ (
+ subq_1.metric_time__day <= subq_2.metric_time__day
+ ) AND (
+ subq_1.metric_time__day > DATE_ADD('day', -2, subq_2.metric_time__day)
+ )
+ ) subq_4
+ ON
+ DATE_ADD('day', -2, subq_5.metric_time__day) = subq_4.metric_time__day
+ ) subq_7
+ ) subq_8
+ WHERE subq_8.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02'
+ ) subq_9
+ GROUP BY
+ subq_9.metric_time__day
+ ) subq_10
+) subq_11
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql
new file mode 100644
index 0000000000..2d70867cb1
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_cumulative_time_offset_metric_with_time_constraint__plan0_optimized.sql
@@ -0,0 +1,42 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago
+FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookers', 'metric_time__day']
+ -- Constrain Time Range to [2019-12-19T00:00:00, 2020-01-02T00:00:00]
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_17.metric_time__day AS metric_time__day
+ , COUNT(DISTINCT subq_16.bookers) AS every_2_days_bookers_2_days_ago
+ FROM (
+ -- Date Spine
+ SELECT
+ ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_18
+ WHERE ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02'
+ ) subq_17
+ INNER JOIN (
+ -- Join Self Over Time Range
+ SELECT
+ subq_15.ds AS metric_time__day
+ , bookings_source_src_10001.guest_id AS bookers
+ FROM ***************************.mf_time_spine subq_15
+ INNER JOIN
+ ***************************.fct_bookings bookings_source_src_10001
+ ON
+ (
+ DATE_TRUNC('day', bookings_source_src_10001.ds) <= subq_15.ds
+ ) AND (
+ DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_ADD('day', -2, subq_15.ds)
+ )
+ ) subq_16
+ ON
+ DATE_ADD('day', -2, subq_17.metric_time__day) = subq_16.metric_time__day
+ WHERE subq_17.metric_time__day BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02'
+ GROUP BY
+ subq_17.metric_time__day
+) subq_23
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql
new file mode 100644
index 0000000000..564d6e351d
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0.sql
@@ -0,0 +1,447 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_10.metric_time__day
+ , (bookings - ref_bookings) * 1.0 / bookings AS non_referred_bookings_pct
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day
+ , MAX(subq_4.ref_bookings) AS ref_bookings
+ , MAX(subq_9.bookings) AS bookings
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.referred_bookings AS ref_bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , SUM(subq_2.referred_bookings) AS referred_bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['referred_bookings', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.referred_bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ ) subq_3
+ ) subq_4
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_8.metric_time__day
+ , subq_8.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_7.metric_time__day
+ , SUM(subq_7.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.ds_partitioned__day
+ , subq_5.ds_partitioned__week
+ , subq_5.ds_partitioned__month
+ , subq_5.ds_partitioned__quarter
+ , subq_5.ds_partitioned__year
+ , subq_5.ds_partitioned__extract_year
+ , subq_5.ds_partitioned__extract_quarter
+ , subq_5.ds_partitioned__extract_month
+ , subq_5.ds_partitioned__extract_day
+ , subq_5.ds_partitioned__extract_dow
+ , subq_5.ds_partitioned__extract_doy
+ , subq_5.paid_at__day
+ , subq_5.paid_at__week
+ , subq_5.paid_at__month
+ , subq_5.paid_at__quarter
+ , subq_5.paid_at__year
+ , subq_5.paid_at__extract_year
+ , subq_5.paid_at__extract_quarter
+ , subq_5.paid_at__extract_month
+ , subq_5.paid_at__extract_day
+ , subq_5.paid_at__extract_dow
+ , subq_5.paid_at__extract_doy
+ , subq_5.booking__ds__day
+ , subq_5.booking__ds__week
+ , subq_5.booking__ds__month
+ , subq_5.booking__ds__quarter
+ , subq_5.booking__ds__year
+ , subq_5.booking__ds__extract_year
+ , subq_5.booking__ds__extract_quarter
+ , subq_5.booking__ds__extract_month
+ , subq_5.booking__ds__extract_day
+ , subq_5.booking__ds__extract_dow
+ , subq_5.booking__ds__extract_doy
+ , subq_5.booking__ds_partitioned__day
+ , subq_5.booking__ds_partitioned__week
+ , subq_5.booking__ds_partitioned__month
+ , subq_5.booking__ds_partitioned__quarter
+ , subq_5.booking__ds_partitioned__year
+ , subq_5.booking__ds_partitioned__extract_year
+ , subq_5.booking__ds_partitioned__extract_quarter
+ , subq_5.booking__ds_partitioned__extract_month
+ , subq_5.booking__ds_partitioned__extract_day
+ , subq_5.booking__ds_partitioned__extract_dow
+ , subq_5.booking__ds_partitioned__extract_doy
+ , subq_5.booking__paid_at__day
+ , subq_5.booking__paid_at__week
+ , subq_5.booking__paid_at__month
+ , subq_5.booking__paid_at__quarter
+ , subq_5.booking__paid_at__year
+ , subq_5.booking__paid_at__extract_year
+ , subq_5.booking__paid_at__extract_quarter
+ , subq_5.booking__paid_at__extract_month
+ , subq_5.booking__paid_at__extract_day
+ , subq_5.booking__paid_at__extract_dow
+ , subq_5.booking__paid_at__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.listing
+ , subq_5.guest
+ , subq_5.host
+ , subq_5.booking__listing
+ , subq_5.booking__guest
+ , subq_5.booking__host
+ , subq_5.is_instant
+ , subq_5.booking__is_instant
+ , subq_5.bookings
+ , subq_5.instant_bookings
+ , subq_5.booking_value
+ , subq_5.max_booking_value
+ , subq_5.min_booking_value
+ , subq_5.bookers
+ , subq_5.average_booking_value
+ , subq_5.referred_bookings
+ , subq_5.median_booking_value
+ , subq_5.booking_value_p99
+ , subq_5.discrete_booking_value_p99
+ , subq_5.approximate_continuous_booking_value_p99
+ , subq_5.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_5
+ ) subq_6
+ ) subq_7
+ GROUP BY
+ subq_7.metric_time__day
+ ) subq_8
+ ) subq_9
+ ON
+ subq_4.metric_time__day = subq_9.metric_time__day
+ GROUP BY
+ COALESCE(subq_4.metric_time__day, subq_9.metric_time__day)
+) subq_10
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql
new file mode 100644
index 0000000000..b3e757c0c6
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric__plan0_optimized.sql
@@ -0,0 +1,53 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , (bookings - ref_bookings) * 1.0 / bookings AS non_referred_bookings_pct
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_15.metric_time__day, subq_20.metric_time__day) AS metric_time__day
+ , MAX(subq_15.ref_bookings) AS ref_bookings
+ , MAX(subq_20.bookings) AS bookings
+ FROM (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(referred_bookings) AS ref_bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['referred_bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_13
+ GROUP BY
+ metric_time__day
+ ) subq_15
+ FULL OUTER JOIN (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_18
+ GROUP BY
+ metric_time__day
+ ) subq_20
+ ON
+ subq_15.metric_time__day = subq_20.metric_time__day
+ GROUP BY
+ COALESCE(subq_15.metric_time__day, subq_20.metric_time__day)
+) subq_21
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
new file mode 100644
index 0000000000..6823712051
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0.sql
@@ -0,0 +1,100 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_7.metric_time__month
+ , bookings_last_month AS bookings_last_month
+FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_6.metric_time__month
+ , subq_6.bookings_monthly AS bookings_last_month
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_5.metric_time__month
+ , SUM(subq_5.bookings_monthly) AS bookings_monthly
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings_monthly', 'metric_time__month']
+ SELECT
+ subq_4.metric_time__month
+ , subq_4.bookings_monthly
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_2.metric_time__month AS metric_time__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
+ , subq_1.monthly_ds__extract_year AS monthly_ds__extract_year
+ , subq_1.monthly_ds__extract_quarter AS monthly_ds__extract_quarter
+ , subq_1.monthly_ds__extract_month AS monthly_ds__extract_month
+ , subq_1.booking__monthly_ds__month AS booking__monthly_ds__month
+ , subq_1.booking__monthly_ds__quarter AS booking__monthly_ds__quarter
+ , subq_1.booking__monthly_ds__year AS booking__monthly_ds__year
+ , subq_1.booking__monthly_ds__extract_year AS booking__monthly_ds__extract_year
+ , subq_1.booking__monthly_ds__extract_quarter AS booking__monthly_ds__extract_quarter
+ , subq_1.booking__monthly_ds__extract_month AS booking__monthly_ds__extract_month
+ , subq_1.listing AS listing
+ , subq_1.booking__listing AS booking__listing
+ , subq_1.bookings_monthly AS bookings_monthly
+ FROM (
+ -- Date Spine
+ SELECT
+ DATE_TRUNC('month', subq_3.ds) AS metric_time__month
+ FROM ***************************.mf_time_spine subq_3
+ GROUP BY
+ DATE_TRUNC('month', subq_3.ds)
+ ) subq_2
+ INNER JOIN (
+ -- Metric Time Dimension 'monthly_ds'
+ SELECT
+ subq_0.monthly_ds__month
+ , subq_0.monthly_ds__quarter
+ , subq_0.monthly_ds__year
+ , subq_0.monthly_ds__extract_year
+ , subq_0.monthly_ds__extract_quarter
+ , subq_0.monthly_ds__extract_month
+ , subq_0.booking__monthly_ds__month
+ , subq_0.booking__monthly_ds__quarter
+ , subq_0.booking__monthly_ds__year
+ , subq_0.booking__monthly_ds__extract_year
+ , subq_0.booking__monthly_ds__extract_quarter
+ , subq_0.booking__monthly_ds__extract_month
+ , subq_0.monthly_ds__month AS metric_time__month
+ , subq_0.monthly_ds__quarter AS metric_time__quarter
+ , subq_0.monthly_ds__year AS metric_time__year
+ , subq_0.monthly_ds__extract_year AS metric_time__extract_year
+ , subq_0.monthly_ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.monthly_ds__extract_month AS metric_time__extract_month
+ , subq_0.listing
+ , subq_0.booking__listing
+ , subq_0.bookings_monthly
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_monthly_source'
+ SELECT
+ bookings_monthly_source_src_10026.bookings_monthly
+ , DATE_TRUNC('month', bookings_monthly_source_src_10026.ds) AS monthly_ds__month
+ , DATE_TRUNC('quarter', bookings_monthly_source_src_10026.ds) AS monthly_ds__quarter
+ , DATE_TRUNC('year', bookings_monthly_source_src_10026.ds) AS monthly_ds__year
+ , EXTRACT(year FROM bookings_monthly_source_src_10026.ds) AS monthly_ds__extract_year
+ , EXTRACT(quarter FROM bookings_monthly_source_src_10026.ds) AS monthly_ds__extract_quarter
+ , EXTRACT(month FROM bookings_monthly_source_src_10026.ds) AS monthly_ds__extract_month
+ , DATE_TRUNC('month', bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__month
+ , DATE_TRUNC('quarter', bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__quarter
+ , DATE_TRUNC('year', bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__year
+ , EXTRACT(year FROM bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__extract_year
+ , EXTRACT(quarter FROM bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__extract_quarter
+ , EXTRACT(month FROM bookings_monthly_source_src_10026.ds) AS booking__monthly_ds__extract_month
+ , bookings_monthly_source_src_10026.listing_id AS listing
+ , bookings_monthly_source_src_10026.listing_id AS booking__listing
+ FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10026
+ ) subq_0
+ ) subq_1
+ ON
+ DATE_ADD('month', -1, subq_2.metric_time__month) = subq_1.metric_time__month
+ ) subq_4
+ ) subq_5
+ GROUP BY
+ subq_5.metric_time__month
+ ) subq_6
+) subq_7
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql
new file mode 100644
index 0000000000..583a06e6b4
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_month_dimension_and_offset_window__plan0_optimized.sql
@@ -0,0 +1,28 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__month
+ , bookings_last_month AS bookings_last_month
+FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings_monthly', 'metric_time__month']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_10.metric_time__month AS metric_time__month
+ , SUM(bookings_monthly_source_src_10026.bookings_monthly) AS bookings_last_month
+ FROM (
+ -- Date Spine
+ SELECT
+ DATE_TRUNC('month', ds) AS metric_time__month
+ FROM ***************************.mf_time_spine subq_11
+ GROUP BY
+ DATE_TRUNC('month', ds)
+ ) subq_10
+ INNER JOIN
+ ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_10026
+ ON
+ DATE_ADD('month', -1, subq_10.metric_time__month) = DATE_TRUNC('month', bookings_monthly_source_src_10026.ds)
+ GROUP BY
+ subq_10.metric_time__month
+) subq_15
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
new file mode 100644
index 0000000000..17e672d736
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0.sql
@@ -0,0 +1,547 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_13.metric_time__day
+ , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) AS metric_time__day
+ , MAX(subq_4.bookings) AS bookings
+ , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ ) subq_3
+ ) subq_4
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_11.metric_time__day
+ , subq_11.bookings AS bookings_at_start_of_month
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_10.metric_time__day
+ , SUM(subq_10.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_9.metric_time__day
+ , subq_9.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_7.metric_time__day AS metric_time__day
+ , subq_6.ds__day AS ds__day
+ , subq_6.ds__week AS ds__week
+ , subq_6.ds__month AS ds__month
+ , subq_6.ds__quarter AS ds__quarter
+ , subq_6.ds__year AS ds__year
+ , subq_6.ds__extract_year AS ds__extract_year
+ , subq_6.ds__extract_quarter AS ds__extract_quarter
+ , subq_6.ds__extract_month AS ds__extract_month
+ , subq_6.ds__extract_day AS ds__extract_day
+ , subq_6.ds__extract_dow AS ds__extract_dow
+ , subq_6.ds__extract_doy AS ds__extract_doy
+ , subq_6.ds_partitioned__day AS ds_partitioned__day
+ , subq_6.ds_partitioned__week AS ds_partitioned__week
+ , subq_6.ds_partitioned__month AS ds_partitioned__month
+ , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_6.ds_partitioned__year AS ds_partitioned__year
+ , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_6.paid_at__day AS paid_at__day
+ , subq_6.paid_at__week AS paid_at__week
+ , subq_6.paid_at__month AS paid_at__month
+ , subq_6.paid_at__quarter AS paid_at__quarter
+ , subq_6.paid_at__year AS paid_at__year
+ , subq_6.paid_at__extract_year AS paid_at__extract_year
+ , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_6.paid_at__extract_month AS paid_at__extract_month
+ , subq_6.paid_at__extract_day AS paid_at__extract_day
+ , subq_6.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_6.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_6.booking__ds__day AS booking__ds__day
+ , subq_6.booking__ds__week AS booking__ds__week
+ , subq_6.booking__ds__month AS booking__ds__month
+ , subq_6.booking__ds__quarter AS booking__ds__quarter
+ , subq_6.booking__ds__year AS booking__ds__year
+ , subq_6.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_6.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_6.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_6.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_6.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_6.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_6.booking__paid_at__day AS booking__paid_at__day
+ , subq_6.booking__paid_at__week AS booking__paid_at__week
+ , subq_6.booking__paid_at__month AS booking__paid_at__month
+ , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_6.booking__paid_at__year AS booking__paid_at__year
+ , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_6.listing AS listing
+ , subq_6.guest AS guest
+ , subq_6.host AS host
+ , subq_6.booking__listing AS booking__listing
+ , subq_6.booking__guest AS booking__guest
+ , subq_6.booking__host AS booking__host
+ , subq_6.is_instant AS is_instant
+ , subq_6.booking__is_instant AS booking__is_instant
+ , subq_6.bookings AS bookings
+ , subq_6.instant_bookings AS instant_bookings
+ , subq_6.booking_value AS booking_value
+ , subq_6.max_booking_value AS max_booking_value
+ , subq_6.min_booking_value AS min_booking_value
+ , subq_6.bookers AS bookers
+ , subq_6.average_booking_value AS average_booking_value
+ , subq_6.referred_bookings AS referred_bookings
+ , subq_6.median_booking_value AS median_booking_value
+ , subq_6.booking_value_p99 AS booking_value_p99
+ , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_8.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_8
+ ) subq_7
+ INNER JOIN (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.ds_partitioned__day
+ , subq_5.ds_partitioned__week
+ , subq_5.ds_partitioned__month
+ , subq_5.ds_partitioned__quarter
+ , subq_5.ds_partitioned__year
+ , subq_5.ds_partitioned__extract_year
+ , subq_5.ds_partitioned__extract_quarter
+ , subq_5.ds_partitioned__extract_month
+ , subq_5.ds_partitioned__extract_day
+ , subq_5.ds_partitioned__extract_dow
+ , subq_5.ds_partitioned__extract_doy
+ , subq_5.paid_at__day
+ , subq_5.paid_at__week
+ , subq_5.paid_at__month
+ , subq_5.paid_at__quarter
+ , subq_5.paid_at__year
+ , subq_5.paid_at__extract_year
+ , subq_5.paid_at__extract_quarter
+ , subq_5.paid_at__extract_month
+ , subq_5.paid_at__extract_day
+ , subq_5.paid_at__extract_dow
+ , subq_5.paid_at__extract_doy
+ , subq_5.booking__ds__day
+ , subq_5.booking__ds__week
+ , subq_5.booking__ds__month
+ , subq_5.booking__ds__quarter
+ , subq_5.booking__ds__year
+ , subq_5.booking__ds__extract_year
+ , subq_5.booking__ds__extract_quarter
+ , subq_5.booking__ds__extract_month
+ , subq_5.booking__ds__extract_day
+ , subq_5.booking__ds__extract_dow
+ , subq_5.booking__ds__extract_doy
+ , subq_5.booking__ds_partitioned__day
+ , subq_5.booking__ds_partitioned__week
+ , subq_5.booking__ds_partitioned__month
+ , subq_5.booking__ds_partitioned__quarter
+ , subq_5.booking__ds_partitioned__year
+ , subq_5.booking__ds_partitioned__extract_year
+ , subq_5.booking__ds_partitioned__extract_quarter
+ , subq_5.booking__ds_partitioned__extract_month
+ , subq_5.booking__ds_partitioned__extract_day
+ , subq_5.booking__ds_partitioned__extract_dow
+ , subq_5.booking__ds_partitioned__extract_doy
+ , subq_5.booking__paid_at__day
+ , subq_5.booking__paid_at__week
+ , subq_5.booking__paid_at__month
+ , subq_5.booking__paid_at__quarter
+ , subq_5.booking__paid_at__year
+ , subq_5.booking__paid_at__extract_year
+ , subq_5.booking__paid_at__extract_quarter
+ , subq_5.booking__paid_at__extract_month
+ , subq_5.booking__paid_at__extract_day
+ , subq_5.booking__paid_at__extract_dow
+ , subq_5.booking__paid_at__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.listing
+ , subq_5.guest
+ , subq_5.host
+ , subq_5.booking__listing
+ , subq_5.booking__guest
+ , subq_5.booking__host
+ , subq_5.is_instant
+ , subq_5.booking__is_instant
+ , subq_5.bookings
+ , subq_5.instant_bookings
+ , subq_5.booking_value
+ , subq_5.max_booking_value
+ , subq_5.min_booking_value
+ , subq_5.bookers
+ , subq_5.average_booking_value
+ , subq_5.referred_bookings
+ , subq_5.median_booking_value
+ , subq_5.booking_value_p99
+ , subq_5.discrete_booking_value_p99
+ , subq_5.approximate_continuous_booking_value_p99
+ , subq_5.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_5
+ ) subq_6
+ ON
+ DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day
+ ) subq_9
+ ) subq_10
+ GROUP BY
+ subq_10.metric_time__day
+ ) subq_11
+ ) subq_12
+ ON
+ subq_4.metric_time__day = subq_12.metric_time__day
+ GROUP BY
+ COALESCE(subq_4.metric_time__day, subq_12.metric_time__day)
+) subq_13
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql
new file mode 100644
index 0000000000..3763e526e9
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain__plan0_optimized.sql
@@ -0,0 +1,57 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day
+ , MAX(subq_18.bookings) AS bookings
+ , MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month
+ FROM (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_16
+ GROUP BY
+ metric_time__day
+ ) subq_18
+ FULL OUTER JOIN (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_22.ds AS metric_time__day
+ , SUM(subq_20.bookings) AS bookings_at_start_of_month
+ FROM ***************************.mf_time_spine subq_22
+ 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_10001
+ ) subq_20
+ ON
+ DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day
+ GROUP BY
+ subq_22.ds
+ ) subq_26
+ ON
+ subq_18.metric_time__day = subq_26.metric_time__day
+ GROUP BY
+ COALESCE(subq_18.metric_time__day, subq_26.metric_time__day)
+) subq_27
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
new file mode 100644
index 0000000000..bf6bf89e6c
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0.sql
@@ -0,0 +1,548 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_13.metric_time__week
+ , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_4.metric_time__week, subq_12.metric_time__week) AS metric_time__week
+ , MAX(subq_4.bookings) AS bookings
+ , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__week
+ , subq_3.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__week
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__week']
+ SELECT
+ subq_1.metric_time__week
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__week
+ ) subq_3
+ ) subq_4
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_11.metric_time__week
+ , subq_11.bookings AS bookings_at_start_of_month
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_10.metric_time__week
+ , SUM(subq_10.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__week']
+ SELECT
+ subq_9.metric_time__week
+ , subq_9.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week
+ , subq_6.ds__day AS ds__day
+ , subq_6.ds__week AS ds__week
+ , subq_6.ds__month AS ds__month
+ , subq_6.ds__quarter AS ds__quarter
+ , subq_6.ds__year AS ds__year
+ , subq_6.ds__extract_year AS ds__extract_year
+ , subq_6.ds__extract_quarter AS ds__extract_quarter
+ , subq_6.ds__extract_month AS ds__extract_month
+ , subq_6.ds__extract_day AS ds__extract_day
+ , subq_6.ds__extract_dow AS ds__extract_dow
+ , subq_6.ds__extract_doy AS ds__extract_doy
+ , subq_6.ds_partitioned__day AS ds_partitioned__day
+ , subq_6.ds_partitioned__week AS ds_partitioned__week
+ , subq_6.ds_partitioned__month AS ds_partitioned__month
+ , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_6.ds_partitioned__year AS ds_partitioned__year
+ , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_6.paid_at__day AS paid_at__day
+ , subq_6.paid_at__week AS paid_at__week
+ , subq_6.paid_at__month AS paid_at__month
+ , subq_6.paid_at__quarter AS paid_at__quarter
+ , subq_6.paid_at__year AS paid_at__year
+ , subq_6.paid_at__extract_year AS paid_at__extract_year
+ , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_6.paid_at__extract_month AS paid_at__extract_month
+ , subq_6.paid_at__extract_day AS paid_at__extract_day
+ , subq_6.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_6.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_6.booking__ds__day AS booking__ds__day
+ , subq_6.booking__ds__week AS booking__ds__week
+ , subq_6.booking__ds__month AS booking__ds__month
+ , subq_6.booking__ds__quarter AS booking__ds__quarter
+ , subq_6.booking__ds__year AS booking__ds__year
+ , subq_6.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_6.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_6.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_6.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_6.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_6.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_6.booking__paid_at__day AS booking__paid_at__day
+ , subq_6.booking__paid_at__week AS booking__paid_at__week
+ , subq_6.booking__paid_at__month AS booking__paid_at__month
+ , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_6.booking__paid_at__year AS booking__paid_at__year
+ , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_6.listing AS listing
+ , subq_6.guest AS guest
+ , subq_6.host AS host
+ , subq_6.booking__listing AS booking__listing
+ , subq_6.booking__guest AS booking__guest
+ , subq_6.booking__host AS booking__host
+ , subq_6.is_instant AS is_instant
+ , subq_6.booking__is_instant AS booking__is_instant
+ , subq_6.bookings AS bookings
+ , subq_6.instant_bookings AS instant_bookings
+ , subq_6.booking_value AS booking_value
+ , subq_6.max_booking_value AS max_booking_value
+ , subq_6.min_booking_value AS min_booking_value
+ , subq_6.bookers AS bookers
+ , subq_6.average_booking_value AS average_booking_value
+ , subq_6.referred_bookings AS referred_bookings
+ , subq_6.median_booking_value AS median_booking_value
+ , subq_6.booking_value_p99 AS booking_value_p99
+ , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_8.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_8
+ ) subq_7
+ INNER JOIN (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.ds_partitioned__day
+ , subq_5.ds_partitioned__week
+ , subq_5.ds_partitioned__month
+ , subq_5.ds_partitioned__quarter
+ , subq_5.ds_partitioned__year
+ , subq_5.ds_partitioned__extract_year
+ , subq_5.ds_partitioned__extract_quarter
+ , subq_5.ds_partitioned__extract_month
+ , subq_5.ds_partitioned__extract_day
+ , subq_5.ds_partitioned__extract_dow
+ , subq_5.ds_partitioned__extract_doy
+ , subq_5.paid_at__day
+ , subq_5.paid_at__week
+ , subq_5.paid_at__month
+ , subq_5.paid_at__quarter
+ , subq_5.paid_at__year
+ , subq_5.paid_at__extract_year
+ , subq_5.paid_at__extract_quarter
+ , subq_5.paid_at__extract_month
+ , subq_5.paid_at__extract_day
+ , subq_5.paid_at__extract_dow
+ , subq_5.paid_at__extract_doy
+ , subq_5.booking__ds__day
+ , subq_5.booking__ds__week
+ , subq_5.booking__ds__month
+ , subq_5.booking__ds__quarter
+ , subq_5.booking__ds__year
+ , subq_5.booking__ds__extract_year
+ , subq_5.booking__ds__extract_quarter
+ , subq_5.booking__ds__extract_month
+ , subq_5.booking__ds__extract_day
+ , subq_5.booking__ds__extract_dow
+ , subq_5.booking__ds__extract_doy
+ , subq_5.booking__ds_partitioned__day
+ , subq_5.booking__ds_partitioned__week
+ , subq_5.booking__ds_partitioned__month
+ , subq_5.booking__ds_partitioned__quarter
+ , subq_5.booking__ds_partitioned__year
+ , subq_5.booking__ds_partitioned__extract_year
+ , subq_5.booking__ds_partitioned__extract_quarter
+ , subq_5.booking__ds_partitioned__extract_month
+ , subq_5.booking__ds_partitioned__extract_day
+ , subq_5.booking__ds_partitioned__extract_dow
+ , subq_5.booking__ds_partitioned__extract_doy
+ , subq_5.booking__paid_at__day
+ , subq_5.booking__paid_at__week
+ , subq_5.booking__paid_at__month
+ , subq_5.booking__paid_at__quarter
+ , subq_5.booking__paid_at__year
+ , subq_5.booking__paid_at__extract_year
+ , subq_5.booking__paid_at__extract_quarter
+ , subq_5.booking__paid_at__extract_month
+ , subq_5.booking__paid_at__extract_day
+ , subq_5.booking__paid_at__extract_dow
+ , subq_5.booking__paid_at__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.listing
+ , subq_5.guest
+ , subq_5.host
+ , subq_5.booking__listing
+ , subq_5.booking__guest
+ , subq_5.booking__host
+ , subq_5.is_instant
+ , subq_5.booking__is_instant
+ , subq_5.bookings
+ , subq_5.instant_bookings
+ , subq_5.booking_value
+ , subq_5.max_booking_value
+ , subq_5.min_booking_value
+ , subq_5.bookers
+ , subq_5.average_booking_value
+ , subq_5.referred_bookings
+ , subq_5.median_booking_value
+ , subq_5.booking_value_p99
+ , subq_5.discrete_booking_value_p99
+ , subq_5.approximate_continuous_booking_value_p99
+ , subq_5.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_5
+ ) subq_6
+ ON
+ DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day
+ WHERE DATE_TRUNC('week', subq_7.metric_time__day) = subq_7.metric_time__day
+ ) subq_9
+ ) subq_10
+ GROUP BY
+ subq_10.metric_time__week
+ ) subq_11
+ ) subq_12
+ ON
+ subq_4.metric_time__week = subq_12.metric_time__week
+ GROUP BY
+ COALESCE(subq_4.metric_time__week, subq_12.metric_time__week)
+) subq_13
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql
new file mode 100644
index 0000000000..0ac0bf4ca1
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_to_grain_and_granularity__plan0_optimized.sql
@@ -0,0 +1,58 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__week
+ , bookings - bookings_at_start_of_month AS bookings_growth_since_start_of_month
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_18.metric_time__week, subq_26.metric_time__week) AS metric_time__week
+ , MAX(subq_18.bookings) AS bookings
+ , MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month
+ FROM (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__week
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__week']
+ SELECT
+ DATE_TRUNC('week', ds) AS metric_time__week
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_16
+ GROUP BY
+ metric_time__week
+ ) subq_18
+ FULL OUTER JOIN (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__week']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ DATE_TRUNC('week', subq_22.ds) AS metric_time__week
+ , SUM(subq_20.bookings) AS bookings_at_start_of_month
+ FROM ***************************.mf_time_spine subq_22
+ 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_10001
+ ) subq_20
+ ON
+ DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day
+ WHERE DATE_TRUNC('week', subq_22.ds) = subq_22.ds
+ GROUP BY
+ DATE_TRUNC('week', subq_22.ds)
+ ) subq_26
+ ON
+ subq_18.metric_time__week = subq_26.metric_time__week
+ GROUP BY
+ COALESCE(subq_18.metric_time__week, subq_26.metric_time__week)
+) subq_27
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
new file mode 100644
index 0000000000..26749f75df
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0.sql
@@ -0,0 +1,547 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_13.metric_time__day
+ , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) AS metric_time__day
+ , MAX(subq_4.bookings) AS bookings
+ , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ ) subq_3
+ ) subq_4
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_11.metric_time__day
+ , subq_11.bookings AS bookings_2_weeks_ago
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_10.metric_time__day
+ , SUM(subq_10.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_9.metric_time__day
+ , subq_9.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_7.metric_time__day AS metric_time__day
+ , subq_6.ds__day AS ds__day
+ , subq_6.ds__week AS ds__week
+ , subq_6.ds__month AS ds__month
+ , subq_6.ds__quarter AS ds__quarter
+ , subq_6.ds__year AS ds__year
+ , subq_6.ds__extract_year AS ds__extract_year
+ , subq_6.ds__extract_quarter AS ds__extract_quarter
+ , subq_6.ds__extract_month AS ds__extract_month
+ , subq_6.ds__extract_day AS ds__extract_day
+ , subq_6.ds__extract_dow AS ds__extract_dow
+ , subq_6.ds__extract_doy AS ds__extract_doy
+ , subq_6.ds_partitioned__day AS ds_partitioned__day
+ , subq_6.ds_partitioned__week AS ds_partitioned__week
+ , subq_6.ds_partitioned__month AS ds_partitioned__month
+ , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_6.ds_partitioned__year AS ds_partitioned__year
+ , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_6.paid_at__day AS paid_at__day
+ , subq_6.paid_at__week AS paid_at__week
+ , subq_6.paid_at__month AS paid_at__month
+ , subq_6.paid_at__quarter AS paid_at__quarter
+ , subq_6.paid_at__year AS paid_at__year
+ , subq_6.paid_at__extract_year AS paid_at__extract_year
+ , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_6.paid_at__extract_month AS paid_at__extract_month
+ , subq_6.paid_at__extract_day AS paid_at__extract_day
+ , subq_6.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_6.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_6.booking__ds__day AS booking__ds__day
+ , subq_6.booking__ds__week AS booking__ds__week
+ , subq_6.booking__ds__month AS booking__ds__month
+ , subq_6.booking__ds__quarter AS booking__ds__quarter
+ , subq_6.booking__ds__year AS booking__ds__year
+ , subq_6.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_6.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_6.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_6.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_6.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_6.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_6.booking__paid_at__day AS booking__paid_at__day
+ , subq_6.booking__paid_at__week AS booking__paid_at__week
+ , subq_6.booking__paid_at__month AS booking__paid_at__month
+ , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_6.booking__paid_at__year AS booking__paid_at__year
+ , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_6.listing AS listing
+ , subq_6.guest AS guest
+ , subq_6.host AS host
+ , subq_6.booking__listing AS booking__listing
+ , subq_6.booking__guest AS booking__guest
+ , subq_6.booking__host AS booking__host
+ , subq_6.is_instant AS is_instant
+ , subq_6.booking__is_instant AS booking__is_instant
+ , subq_6.bookings AS bookings
+ , subq_6.instant_bookings AS instant_bookings
+ , subq_6.booking_value AS booking_value
+ , subq_6.max_booking_value AS max_booking_value
+ , subq_6.min_booking_value AS min_booking_value
+ , subq_6.bookers AS bookers
+ , subq_6.average_booking_value AS average_booking_value
+ , subq_6.referred_bookings AS referred_bookings
+ , subq_6.median_booking_value AS median_booking_value
+ , subq_6.booking_value_p99 AS booking_value_p99
+ , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_8.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_8
+ ) subq_7
+ INNER JOIN (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.ds_partitioned__day
+ , subq_5.ds_partitioned__week
+ , subq_5.ds_partitioned__month
+ , subq_5.ds_partitioned__quarter
+ , subq_5.ds_partitioned__year
+ , subq_5.ds_partitioned__extract_year
+ , subq_5.ds_partitioned__extract_quarter
+ , subq_5.ds_partitioned__extract_month
+ , subq_5.ds_partitioned__extract_day
+ , subq_5.ds_partitioned__extract_dow
+ , subq_5.ds_partitioned__extract_doy
+ , subq_5.paid_at__day
+ , subq_5.paid_at__week
+ , subq_5.paid_at__month
+ , subq_5.paid_at__quarter
+ , subq_5.paid_at__year
+ , subq_5.paid_at__extract_year
+ , subq_5.paid_at__extract_quarter
+ , subq_5.paid_at__extract_month
+ , subq_5.paid_at__extract_day
+ , subq_5.paid_at__extract_dow
+ , subq_5.paid_at__extract_doy
+ , subq_5.booking__ds__day
+ , subq_5.booking__ds__week
+ , subq_5.booking__ds__month
+ , subq_5.booking__ds__quarter
+ , subq_5.booking__ds__year
+ , subq_5.booking__ds__extract_year
+ , subq_5.booking__ds__extract_quarter
+ , subq_5.booking__ds__extract_month
+ , subq_5.booking__ds__extract_day
+ , subq_5.booking__ds__extract_dow
+ , subq_5.booking__ds__extract_doy
+ , subq_5.booking__ds_partitioned__day
+ , subq_5.booking__ds_partitioned__week
+ , subq_5.booking__ds_partitioned__month
+ , subq_5.booking__ds_partitioned__quarter
+ , subq_5.booking__ds_partitioned__year
+ , subq_5.booking__ds_partitioned__extract_year
+ , subq_5.booking__ds_partitioned__extract_quarter
+ , subq_5.booking__ds_partitioned__extract_month
+ , subq_5.booking__ds_partitioned__extract_day
+ , subq_5.booking__ds_partitioned__extract_dow
+ , subq_5.booking__ds_partitioned__extract_doy
+ , subq_5.booking__paid_at__day
+ , subq_5.booking__paid_at__week
+ , subq_5.booking__paid_at__month
+ , subq_5.booking__paid_at__quarter
+ , subq_5.booking__paid_at__year
+ , subq_5.booking__paid_at__extract_year
+ , subq_5.booking__paid_at__extract_quarter
+ , subq_5.booking__paid_at__extract_month
+ , subq_5.booking__paid_at__extract_day
+ , subq_5.booking__paid_at__extract_dow
+ , subq_5.booking__paid_at__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.listing
+ , subq_5.guest
+ , subq_5.host
+ , subq_5.booking__listing
+ , subq_5.booking__guest
+ , subq_5.booking__host
+ , subq_5.is_instant
+ , subq_5.booking__is_instant
+ , subq_5.bookings
+ , subq_5.instant_bookings
+ , subq_5.booking_value
+ , subq_5.max_booking_value
+ , subq_5.min_booking_value
+ , subq_5.bookers
+ , subq_5.average_booking_value
+ , subq_5.referred_bookings
+ , subq_5.median_booking_value
+ , subq_5.booking_value_p99
+ , subq_5.discrete_booking_value_p99
+ , subq_5.approximate_continuous_booking_value_p99
+ , subq_5.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_5
+ ) subq_6
+ ON
+ DATE_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day
+ ) subq_9
+ ) subq_10
+ GROUP BY
+ subq_10.metric_time__day
+ ) subq_11
+ ) subq_12
+ ON
+ subq_4.metric_time__day = subq_12.metric_time__day
+ GROUP BY
+ COALESCE(subq_4.metric_time__day, subq_12.metric_time__day)
+) subq_13
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql
new file mode 100644
index 0000000000..3affc98215
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window__plan0_optimized.sql
@@ -0,0 +1,57 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day
+ , MAX(subq_18.bookings) AS bookings
+ , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago
+ FROM (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_16
+ GROUP BY
+ metric_time__day
+ ) subq_18
+ FULL OUTER JOIN (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_22.ds AS metric_time__day
+ , SUM(subq_20.bookings) AS bookings_2_weeks_ago
+ FROM ***************************.mf_time_spine subq_22
+ 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_10001
+ ) subq_20
+ ON
+ DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day
+ GROUP BY
+ subq_22.ds
+ ) subq_26
+ ON
+ subq_18.metric_time__day = subq_26.metric_time__day
+ GROUP BY
+ COALESCE(subq_18.metric_time__day, subq_26.metric_time__day)
+) subq_27
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
new file mode 100644
index 0000000000..1644094ca9
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0.sql
@@ -0,0 +1,547 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_13.metric_time__quarter
+ , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_4.metric_time__quarter, subq_12.metric_time__quarter) AS metric_time__quarter
+ , MAX(subq_4.bookings) AS bookings
+ , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__quarter
+ , subq_3.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__quarter
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__quarter']
+ SELECT
+ subq_1.metric_time__quarter
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__quarter
+ ) subq_3
+ ) subq_4
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_11.metric_time__quarter
+ , subq_11.bookings AS bookings_2_weeks_ago
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_10.metric_time__quarter
+ , SUM(subq_10.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__quarter']
+ SELECT
+ subq_9.metric_time__quarter
+ , subq_9.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter
+ , subq_6.ds__day AS ds__day
+ , subq_6.ds__week AS ds__week
+ , subq_6.ds__month AS ds__month
+ , subq_6.ds__quarter AS ds__quarter
+ , subq_6.ds__year AS ds__year
+ , subq_6.ds__extract_year AS ds__extract_year
+ , subq_6.ds__extract_quarter AS ds__extract_quarter
+ , subq_6.ds__extract_month AS ds__extract_month
+ , subq_6.ds__extract_day AS ds__extract_day
+ , subq_6.ds__extract_dow AS ds__extract_dow
+ , subq_6.ds__extract_doy AS ds__extract_doy
+ , subq_6.ds_partitioned__day AS ds_partitioned__day
+ , subq_6.ds_partitioned__week AS ds_partitioned__week
+ , subq_6.ds_partitioned__month AS ds_partitioned__month
+ , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_6.ds_partitioned__year AS ds_partitioned__year
+ , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_6.paid_at__day AS paid_at__day
+ , subq_6.paid_at__week AS paid_at__week
+ , subq_6.paid_at__month AS paid_at__month
+ , subq_6.paid_at__quarter AS paid_at__quarter
+ , subq_6.paid_at__year AS paid_at__year
+ , subq_6.paid_at__extract_year AS paid_at__extract_year
+ , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_6.paid_at__extract_month AS paid_at__extract_month
+ , subq_6.paid_at__extract_day AS paid_at__extract_day
+ , subq_6.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_6.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_6.booking__ds__day AS booking__ds__day
+ , subq_6.booking__ds__week AS booking__ds__week
+ , subq_6.booking__ds__month AS booking__ds__month
+ , subq_6.booking__ds__quarter AS booking__ds__quarter
+ , subq_6.booking__ds__year AS booking__ds__year
+ , subq_6.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_6.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_6.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_6.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_6.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_6.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_6.booking__paid_at__day AS booking__paid_at__day
+ , subq_6.booking__paid_at__week AS booking__paid_at__week
+ , subq_6.booking__paid_at__month AS booking__paid_at__month
+ , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_6.booking__paid_at__year AS booking__paid_at__year
+ , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_6.listing AS listing
+ , subq_6.guest AS guest
+ , subq_6.host AS host
+ , subq_6.booking__listing AS booking__listing
+ , subq_6.booking__guest AS booking__guest
+ , subq_6.booking__host AS booking__host
+ , subq_6.is_instant AS is_instant
+ , subq_6.booking__is_instant AS booking__is_instant
+ , subq_6.bookings AS bookings
+ , subq_6.instant_bookings AS instant_bookings
+ , subq_6.booking_value AS booking_value
+ , subq_6.max_booking_value AS max_booking_value
+ , subq_6.min_booking_value AS min_booking_value
+ , subq_6.bookers AS bookers
+ , subq_6.average_booking_value AS average_booking_value
+ , subq_6.referred_bookings AS referred_bookings
+ , subq_6.median_booking_value AS median_booking_value
+ , subq_6.booking_value_p99 AS booking_value_p99
+ , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_8.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_8
+ ) subq_7
+ INNER JOIN (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.ds_partitioned__day
+ , subq_5.ds_partitioned__week
+ , subq_5.ds_partitioned__month
+ , subq_5.ds_partitioned__quarter
+ , subq_5.ds_partitioned__year
+ , subq_5.ds_partitioned__extract_year
+ , subq_5.ds_partitioned__extract_quarter
+ , subq_5.ds_partitioned__extract_month
+ , subq_5.ds_partitioned__extract_day
+ , subq_5.ds_partitioned__extract_dow
+ , subq_5.ds_partitioned__extract_doy
+ , subq_5.paid_at__day
+ , subq_5.paid_at__week
+ , subq_5.paid_at__month
+ , subq_5.paid_at__quarter
+ , subq_5.paid_at__year
+ , subq_5.paid_at__extract_year
+ , subq_5.paid_at__extract_quarter
+ , subq_5.paid_at__extract_month
+ , subq_5.paid_at__extract_day
+ , subq_5.paid_at__extract_dow
+ , subq_5.paid_at__extract_doy
+ , subq_5.booking__ds__day
+ , subq_5.booking__ds__week
+ , subq_5.booking__ds__month
+ , subq_5.booking__ds__quarter
+ , subq_5.booking__ds__year
+ , subq_5.booking__ds__extract_year
+ , subq_5.booking__ds__extract_quarter
+ , subq_5.booking__ds__extract_month
+ , subq_5.booking__ds__extract_day
+ , subq_5.booking__ds__extract_dow
+ , subq_5.booking__ds__extract_doy
+ , subq_5.booking__ds_partitioned__day
+ , subq_5.booking__ds_partitioned__week
+ , subq_5.booking__ds_partitioned__month
+ , subq_5.booking__ds_partitioned__quarter
+ , subq_5.booking__ds_partitioned__year
+ , subq_5.booking__ds_partitioned__extract_year
+ , subq_5.booking__ds_partitioned__extract_quarter
+ , subq_5.booking__ds_partitioned__extract_month
+ , subq_5.booking__ds_partitioned__extract_day
+ , subq_5.booking__ds_partitioned__extract_dow
+ , subq_5.booking__ds_partitioned__extract_doy
+ , subq_5.booking__paid_at__day
+ , subq_5.booking__paid_at__week
+ , subq_5.booking__paid_at__month
+ , subq_5.booking__paid_at__quarter
+ , subq_5.booking__paid_at__year
+ , subq_5.booking__paid_at__extract_year
+ , subq_5.booking__paid_at__extract_quarter
+ , subq_5.booking__paid_at__extract_month
+ , subq_5.booking__paid_at__extract_day
+ , subq_5.booking__paid_at__extract_dow
+ , subq_5.booking__paid_at__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.listing
+ , subq_5.guest
+ , subq_5.host
+ , subq_5.booking__listing
+ , subq_5.booking__guest
+ , subq_5.booking__host
+ , subq_5.is_instant
+ , subq_5.booking__is_instant
+ , subq_5.bookings
+ , subq_5.instant_bookings
+ , subq_5.booking_value
+ , subq_5.max_booking_value
+ , subq_5.min_booking_value
+ , subq_5.bookers
+ , subq_5.average_booking_value
+ , subq_5.referred_bookings
+ , subq_5.median_booking_value
+ , subq_5.booking_value_p99
+ , subq_5.discrete_booking_value_p99
+ , subq_5.approximate_continuous_booking_value_p99
+ , subq_5.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_5
+ ) subq_6
+ ON
+ DATE_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day
+ ) subq_9
+ ) subq_10
+ GROUP BY
+ subq_10.metric_time__quarter
+ ) subq_11
+ ) subq_12
+ ON
+ subq_4.metric_time__quarter = subq_12.metric_time__quarter
+ GROUP BY
+ COALESCE(subq_4.metric_time__quarter, subq_12.metric_time__quarter)
+) subq_13
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql
new file mode 100644
index 0000000000..daa0503cca
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_granularity__plan0_optimized.sql
@@ -0,0 +1,57 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__quarter
+ , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_18.metric_time__quarter, subq_26.metric_time__quarter) AS metric_time__quarter
+ , MAX(subq_18.bookings) AS bookings
+ , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago
+ FROM (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__quarter
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__quarter']
+ SELECT
+ DATE_TRUNC('quarter', ds) AS metric_time__quarter
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_16
+ GROUP BY
+ metric_time__quarter
+ ) subq_18
+ FULL OUTER JOIN (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__quarter']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ DATE_TRUNC('quarter', subq_22.ds) AS metric_time__quarter
+ , SUM(subq_20.bookings) AS bookings_2_weeks_ago
+ FROM ***************************.mf_time_spine subq_22
+ 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_10001
+ ) subq_20
+ ON
+ DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day
+ GROUP BY
+ DATE_TRUNC('quarter', subq_22.ds)
+ ) subq_26
+ ON
+ subq_18.metric_time__quarter = subq_26.metric_time__quarter
+ GROUP BY
+ COALESCE(subq_18.metric_time__quarter, subq_26.metric_time__quarter)
+) subq_27
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
new file mode 100644
index 0000000000..b1e0452fac
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0.sql
@@ -0,0 +1,647 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_16.metric_time__day
+ , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) AS metric_time__day
+ , MAX(subq_7.month_start_bookings) AS month_start_bookings
+ , MAX(subq_15.bookings_1_month_ago) AS bookings_1_month_ago
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.bookings AS month_start_bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_5.metric_time__day
+ , SUM(subq_5.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_4.metric_time__day
+ , subq_4.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , 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 (
+ -- Date 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) 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_6
+ ) subq_7
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_14.metric_time__day
+ , subq_14.bookings AS bookings_1_month_ago
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_13.metric_time__day
+ , SUM(subq_13.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_12.metric_time__day
+ , subq_12.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_10.metric_time__day AS metric_time__day
+ , subq_9.ds__day AS ds__day
+ , subq_9.ds__week AS ds__week
+ , subq_9.ds__month AS ds__month
+ , subq_9.ds__quarter AS ds__quarter
+ , subq_9.ds__year AS ds__year
+ , subq_9.ds__extract_year AS ds__extract_year
+ , subq_9.ds__extract_quarter AS ds__extract_quarter
+ , subq_9.ds__extract_month AS ds__extract_month
+ , subq_9.ds__extract_day AS ds__extract_day
+ , subq_9.ds__extract_dow AS ds__extract_dow
+ , subq_9.ds__extract_doy AS ds__extract_doy
+ , subq_9.ds_partitioned__day AS ds_partitioned__day
+ , subq_9.ds_partitioned__week AS ds_partitioned__week
+ , subq_9.ds_partitioned__month AS ds_partitioned__month
+ , subq_9.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_9.ds_partitioned__year AS ds_partitioned__year
+ , subq_9.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_9.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_9.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_9.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_9.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_9.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_9.paid_at__day AS paid_at__day
+ , subq_9.paid_at__week AS paid_at__week
+ , subq_9.paid_at__month AS paid_at__month
+ , subq_9.paid_at__quarter AS paid_at__quarter
+ , subq_9.paid_at__year AS paid_at__year
+ , subq_9.paid_at__extract_year AS paid_at__extract_year
+ , subq_9.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_9.paid_at__extract_month AS paid_at__extract_month
+ , subq_9.paid_at__extract_day AS paid_at__extract_day
+ , subq_9.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_9.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_9.booking__ds__day AS booking__ds__day
+ , subq_9.booking__ds__week AS booking__ds__week
+ , subq_9.booking__ds__month AS booking__ds__month
+ , subq_9.booking__ds__quarter AS booking__ds__quarter
+ , subq_9.booking__ds__year AS booking__ds__year
+ , subq_9.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_9.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_9.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_9.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_9.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_9.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_9.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_9.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_9.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_9.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_9.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_9.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_9.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_9.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_9.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_9.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_9.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_9.booking__paid_at__day AS booking__paid_at__day
+ , subq_9.booking__paid_at__week AS booking__paid_at__week
+ , subq_9.booking__paid_at__month AS booking__paid_at__month
+ , subq_9.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_9.booking__paid_at__year AS booking__paid_at__year
+ , subq_9.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_9.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_9.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_9.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_9.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_9.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_9.listing AS listing
+ , subq_9.guest AS guest
+ , subq_9.host AS host
+ , subq_9.booking__listing AS booking__listing
+ , subq_9.booking__guest AS booking__guest
+ , subq_9.booking__host AS booking__host
+ , subq_9.is_instant AS is_instant
+ , subq_9.booking__is_instant AS booking__is_instant
+ , subq_9.bookings AS bookings
+ , subq_9.instant_bookings AS instant_bookings
+ , subq_9.booking_value AS booking_value
+ , subq_9.max_booking_value AS max_booking_value
+ , subq_9.min_booking_value AS min_booking_value
+ , subq_9.bookers AS bookers
+ , subq_9.average_booking_value AS average_booking_value
+ , subq_9.referred_bookings AS referred_bookings
+ , subq_9.median_booking_value AS median_booking_value
+ , subq_9.booking_value_p99 AS booking_value_p99
+ , subq_9.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_9.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_9.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_11.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_11
+ ) subq_10
+ INNER JOIN (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.ds_partitioned__day
+ , subq_8.ds_partitioned__week
+ , subq_8.ds_partitioned__month
+ , subq_8.ds_partitioned__quarter
+ , subq_8.ds_partitioned__year
+ , subq_8.ds_partitioned__extract_year
+ , subq_8.ds_partitioned__extract_quarter
+ , subq_8.ds_partitioned__extract_month
+ , subq_8.ds_partitioned__extract_day
+ , subq_8.ds_partitioned__extract_dow
+ , subq_8.ds_partitioned__extract_doy
+ , subq_8.paid_at__day
+ , subq_8.paid_at__week
+ , subq_8.paid_at__month
+ , subq_8.paid_at__quarter
+ , subq_8.paid_at__year
+ , subq_8.paid_at__extract_year
+ , subq_8.paid_at__extract_quarter
+ , subq_8.paid_at__extract_month
+ , subq_8.paid_at__extract_day
+ , subq_8.paid_at__extract_dow
+ , subq_8.paid_at__extract_doy
+ , subq_8.booking__ds__day
+ , subq_8.booking__ds__week
+ , subq_8.booking__ds__month
+ , subq_8.booking__ds__quarter
+ , subq_8.booking__ds__year
+ , subq_8.booking__ds__extract_year
+ , subq_8.booking__ds__extract_quarter
+ , subq_8.booking__ds__extract_month
+ , subq_8.booking__ds__extract_day
+ , subq_8.booking__ds__extract_dow
+ , subq_8.booking__ds__extract_doy
+ , subq_8.booking__ds_partitioned__day
+ , subq_8.booking__ds_partitioned__week
+ , subq_8.booking__ds_partitioned__month
+ , subq_8.booking__ds_partitioned__quarter
+ , subq_8.booking__ds_partitioned__year
+ , subq_8.booking__ds_partitioned__extract_year
+ , subq_8.booking__ds_partitioned__extract_quarter
+ , subq_8.booking__ds_partitioned__extract_month
+ , subq_8.booking__ds_partitioned__extract_day
+ , subq_8.booking__ds_partitioned__extract_dow
+ , subq_8.booking__ds_partitioned__extract_doy
+ , subq_8.booking__paid_at__day
+ , subq_8.booking__paid_at__week
+ , subq_8.booking__paid_at__month
+ , subq_8.booking__paid_at__quarter
+ , subq_8.booking__paid_at__year
+ , subq_8.booking__paid_at__extract_year
+ , subq_8.booking__paid_at__extract_quarter
+ , subq_8.booking__paid_at__extract_month
+ , subq_8.booking__paid_at__extract_day
+ , subq_8.booking__paid_at__extract_dow
+ , subq_8.booking__paid_at__extract_doy
+ , subq_8.ds__day AS metric_time__day
+ , subq_8.ds__week AS metric_time__week
+ , subq_8.ds__month AS metric_time__month
+ , subq_8.ds__quarter AS metric_time__quarter
+ , subq_8.ds__year AS metric_time__year
+ , subq_8.ds__extract_year AS metric_time__extract_year
+ , subq_8.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_8.ds__extract_month AS metric_time__extract_month
+ , subq_8.ds__extract_day AS metric_time__extract_day
+ , subq_8.ds__extract_dow AS metric_time__extract_dow
+ , subq_8.ds__extract_doy AS metric_time__extract_doy
+ , subq_8.listing
+ , subq_8.guest
+ , subq_8.host
+ , subq_8.booking__listing
+ , subq_8.booking__guest
+ , subq_8.booking__host
+ , subq_8.is_instant
+ , subq_8.booking__is_instant
+ , subq_8.bookings
+ , subq_8.instant_bookings
+ , subq_8.booking_value
+ , subq_8.max_booking_value
+ , subq_8.min_booking_value
+ , subq_8.bookers
+ , subq_8.average_booking_value
+ , subq_8.referred_bookings
+ , subq_8.median_booking_value
+ , subq_8.booking_value_p99
+ , subq_8.discrete_booking_value_p99
+ , subq_8.approximate_continuous_booking_value_p99
+ , subq_8.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_8
+ ) subq_9
+ ON
+ DATE_ADD('month', -1, subq_10.metric_time__day) = subq_9.metric_time__day
+ ) subq_12
+ ) subq_13
+ GROUP BY
+ subq_13.metric_time__day
+ ) subq_14
+ ) subq_15
+ ON
+ subq_7.metric_time__day = subq_15.metric_time__day
+ GROUP BY
+ COALESCE(subq_7.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql
new file mode 100644
index 0000000000..c708273e6e
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain__plan0_optimized.sql
@@ -0,0 +1,61 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_24.month_start_bookings) AS month_start_bookings
+ , MAX(subq_32.bookings_1_month_ago) AS bookings_1_month_ago
+ FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_20.ds AS metric_time__day
+ , SUM(subq_18.bookings) AS month_start_bookings
+ FROM ***************************.mf_time_spine subq_20
+ 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_10001
+ ) subq_18
+ ON
+ DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day
+ GROUP BY
+ subq_20.ds
+ ) subq_24
+ FULL OUTER JOIN (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_28.ds AS metric_time__day
+ , SUM(subq_26.bookings) AS bookings_1_month_ago
+ FROM ***************************.mf_time_spine subq_28
+ 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_10001
+ ) subq_26
+ ON
+ DATE_ADD('month', -1, subq_28.ds) = subq_26.metric_time__day
+ GROUP BY
+ subq_28.ds
+ ) subq_32
+ ON
+ subq_24.metric_time__day = subq_32.metric_time__day
+ GROUP BY
+ COALESCE(subq_24.metric_time__day, subq_32.metric_time__day)
+) subq_33
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
new file mode 100644
index 0000000000..4161462b4d
--- /dev/null
+++ 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
@@ -0,0 +1,648 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_16.metric_time__year
+ , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_7.metric_time__year, subq_15.metric_time__year) AS metric_time__year
+ , MAX(subq_7.month_start_bookings) AS month_start_bookings
+ , MAX(subq_15.bookings_1_month_ago) AS bookings_1_month_ago
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_6.metric_time__year
+ , subq_6.bookings AS month_start_bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_5.metric_time__year
+ , SUM(subq_5.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__year']
+ SELECT
+ subq_4.metric_time__year
+ , subq_4.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ 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 (
+ -- Date 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ON
+ DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day
+ WHERE DATE_TRUNC('year', subq_2.metric_time__day) = subq_2.metric_time__day
+ ) subq_4
+ ) subq_5
+ GROUP BY
+ subq_5.metric_time__year
+ ) subq_6
+ ) subq_7
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_14.metric_time__year
+ , subq_14.bookings AS bookings_1_month_ago
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_13.metric_time__year
+ , SUM(subq_13.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__year']
+ SELECT
+ subq_12.metric_time__year
+ , subq_12.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year
+ , subq_9.ds__day AS ds__day
+ , subq_9.ds__week AS ds__week
+ , subq_9.ds__month AS ds__month
+ , subq_9.ds__quarter AS ds__quarter
+ , subq_9.ds__year AS ds__year
+ , subq_9.ds__extract_year AS ds__extract_year
+ , subq_9.ds__extract_quarter AS ds__extract_quarter
+ , subq_9.ds__extract_month AS ds__extract_month
+ , subq_9.ds__extract_day AS ds__extract_day
+ , subq_9.ds__extract_dow AS ds__extract_dow
+ , subq_9.ds__extract_doy AS ds__extract_doy
+ , subq_9.ds_partitioned__day AS ds_partitioned__day
+ , subq_9.ds_partitioned__week AS ds_partitioned__week
+ , subq_9.ds_partitioned__month AS ds_partitioned__month
+ , subq_9.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_9.ds_partitioned__year AS ds_partitioned__year
+ , subq_9.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_9.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_9.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_9.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_9.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_9.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_9.paid_at__day AS paid_at__day
+ , subq_9.paid_at__week AS paid_at__week
+ , subq_9.paid_at__month AS paid_at__month
+ , subq_9.paid_at__quarter AS paid_at__quarter
+ , subq_9.paid_at__year AS paid_at__year
+ , subq_9.paid_at__extract_year AS paid_at__extract_year
+ , subq_9.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_9.paid_at__extract_month AS paid_at__extract_month
+ , subq_9.paid_at__extract_day AS paid_at__extract_day
+ , subq_9.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_9.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_9.booking__ds__day AS booking__ds__day
+ , subq_9.booking__ds__week AS booking__ds__week
+ , subq_9.booking__ds__month AS booking__ds__month
+ , subq_9.booking__ds__quarter AS booking__ds__quarter
+ , subq_9.booking__ds__year AS booking__ds__year
+ , subq_9.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_9.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_9.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_9.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_9.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_9.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_9.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_9.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_9.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_9.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_9.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_9.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_9.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_9.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_9.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_9.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_9.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_9.booking__paid_at__day AS booking__paid_at__day
+ , subq_9.booking__paid_at__week AS booking__paid_at__week
+ , subq_9.booking__paid_at__month AS booking__paid_at__month
+ , subq_9.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_9.booking__paid_at__year AS booking__paid_at__year
+ , subq_9.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_9.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_9.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_9.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_9.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_9.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_9.listing AS listing
+ , subq_9.guest AS guest
+ , subq_9.host AS host
+ , subq_9.booking__listing AS booking__listing
+ , subq_9.booking__guest AS booking__guest
+ , subq_9.booking__host AS booking__host
+ , subq_9.is_instant AS is_instant
+ , subq_9.booking__is_instant AS booking__is_instant
+ , subq_9.bookings AS bookings
+ , subq_9.instant_bookings AS instant_bookings
+ , subq_9.booking_value AS booking_value
+ , subq_9.max_booking_value AS max_booking_value
+ , subq_9.min_booking_value AS min_booking_value
+ , subq_9.bookers AS bookers
+ , subq_9.average_booking_value AS average_booking_value
+ , subq_9.referred_bookings AS referred_bookings
+ , subq_9.median_booking_value AS median_booking_value
+ , subq_9.booking_value_p99 AS booking_value_p99
+ , subq_9.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_9.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_9.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_11.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_11
+ ) subq_10
+ INNER JOIN (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.ds_partitioned__day
+ , subq_8.ds_partitioned__week
+ , subq_8.ds_partitioned__month
+ , subq_8.ds_partitioned__quarter
+ , subq_8.ds_partitioned__year
+ , subq_8.ds_partitioned__extract_year
+ , subq_8.ds_partitioned__extract_quarter
+ , subq_8.ds_partitioned__extract_month
+ , subq_8.ds_partitioned__extract_day
+ , subq_8.ds_partitioned__extract_dow
+ , subq_8.ds_partitioned__extract_doy
+ , subq_8.paid_at__day
+ , subq_8.paid_at__week
+ , subq_8.paid_at__month
+ , subq_8.paid_at__quarter
+ , subq_8.paid_at__year
+ , subq_8.paid_at__extract_year
+ , subq_8.paid_at__extract_quarter
+ , subq_8.paid_at__extract_month
+ , subq_8.paid_at__extract_day
+ , subq_8.paid_at__extract_dow
+ , subq_8.paid_at__extract_doy
+ , subq_8.booking__ds__day
+ , subq_8.booking__ds__week
+ , subq_8.booking__ds__month
+ , subq_8.booking__ds__quarter
+ , subq_8.booking__ds__year
+ , subq_8.booking__ds__extract_year
+ , subq_8.booking__ds__extract_quarter
+ , subq_8.booking__ds__extract_month
+ , subq_8.booking__ds__extract_day
+ , subq_8.booking__ds__extract_dow
+ , subq_8.booking__ds__extract_doy
+ , subq_8.booking__ds_partitioned__day
+ , subq_8.booking__ds_partitioned__week
+ , subq_8.booking__ds_partitioned__month
+ , subq_8.booking__ds_partitioned__quarter
+ , subq_8.booking__ds_partitioned__year
+ , subq_8.booking__ds_partitioned__extract_year
+ , subq_8.booking__ds_partitioned__extract_quarter
+ , subq_8.booking__ds_partitioned__extract_month
+ , subq_8.booking__ds_partitioned__extract_day
+ , subq_8.booking__ds_partitioned__extract_dow
+ , subq_8.booking__ds_partitioned__extract_doy
+ , subq_8.booking__paid_at__day
+ , subq_8.booking__paid_at__week
+ , subq_8.booking__paid_at__month
+ , subq_8.booking__paid_at__quarter
+ , subq_8.booking__paid_at__year
+ , subq_8.booking__paid_at__extract_year
+ , subq_8.booking__paid_at__extract_quarter
+ , subq_8.booking__paid_at__extract_month
+ , subq_8.booking__paid_at__extract_day
+ , subq_8.booking__paid_at__extract_dow
+ , subq_8.booking__paid_at__extract_doy
+ , subq_8.ds__day AS metric_time__day
+ , subq_8.ds__week AS metric_time__week
+ , subq_8.ds__month AS metric_time__month
+ , subq_8.ds__quarter AS metric_time__quarter
+ , subq_8.ds__year AS metric_time__year
+ , subq_8.ds__extract_year AS metric_time__extract_year
+ , subq_8.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_8.ds__extract_month AS metric_time__extract_month
+ , subq_8.ds__extract_day AS metric_time__extract_day
+ , subq_8.ds__extract_dow AS metric_time__extract_dow
+ , subq_8.ds__extract_doy AS metric_time__extract_doy
+ , subq_8.listing
+ , subq_8.guest
+ , subq_8.host
+ , subq_8.booking__listing
+ , subq_8.booking__guest
+ , subq_8.booking__host
+ , subq_8.is_instant
+ , subq_8.booking__is_instant
+ , subq_8.bookings
+ , subq_8.instant_bookings
+ , subq_8.booking_value
+ , subq_8.max_booking_value
+ , subq_8.min_booking_value
+ , subq_8.bookers
+ , subq_8.average_booking_value
+ , subq_8.referred_bookings
+ , subq_8.median_booking_value
+ , subq_8.booking_value_p99
+ , subq_8.discrete_booking_value_p99
+ , subq_8.approximate_continuous_booking_value_p99
+ , subq_8.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_8
+ ) subq_9
+ ON
+ DATE_ADD('month', -1, subq_10.metric_time__day) = subq_9.metric_time__day
+ ) subq_12
+ ) subq_13
+ GROUP BY
+ subq_13.metric_time__year
+ ) subq_14
+ ) subq_15
+ ON
+ subq_7.metric_time__year = subq_15.metric_time__year
+ GROUP BY
+ COALESCE(subq_7.metric_time__year, subq_15.metric_time__year)
+) subq_16
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_optimized.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_optimized.sql
new file mode 100644
index 0000000000..2c0a228856
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_offset_to_grain_and_granularity__plan0_optimized.sql
@@ -0,0 +1,62 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__year
+ , month_start_bookings - bookings_1_month_ago AS bookings_month_start_compared_to_1_month_prior
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_24.metric_time__year, subq_32.metric_time__year) AS metric_time__year
+ , MAX(subq_24.month_start_bookings) AS month_start_bookings
+ , MAX(subq_32.bookings_1_month_ago) AS bookings_1_month_ago
+ FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__year']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ DATE_TRUNC('year', subq_20.ds) AS metric_time__year
+ , SUM(subq_18.bookings) AS month_start_bookings
+ FROM ***************************.mf_time_spine subq_20
+ 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_10001
+ ) subq_18
+ ON
+ DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day
+ WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds
+ GROUP BY
+ DATE_TRUNC('year', subq_20.ds)
+ ) subq_24
+ FULL OUTER JOIN (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__year']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ DATE_TRUNC('year', subq_28.ds) AS metric_time__year
+ , SUM(subq_26.bookings) AS bookings_1_month_ago
+ FROM ***************************.mf_time_spine subq_28
+ 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_10001
+ ) subq_26
+ ON
+ DATE_ADD('month', -1, subq_28.ds) = subq_26.metric_time__day
+ GROUP BY
+ DATE_TRUNC('year', subq_28.ds)
+ ) subq_32
+ ON
+ subq_24.metric_time__year = subq_32.metric_time__year
+ GROUP BY
+ COALESCE(subq_24.metric_time__year, subq_32.metric_time__year)
+) subq_33
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
new file mode 100644
index 0000000000..44aeb8a341
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0.sql
@@ -0,0 +1,561 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_15.metric_time__day
+ , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_5.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ , MAX(subq_5.bookings) AS bookings
+ , MAX(subq_14.bookings_2_weeks_ago) AS bookings_2_weeks_ago
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_4.metric_time__day
+ , subq_4.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_3.metric_time__day
+ , SUM(subq_3.bookings) AS bookings
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14'
+ ) subq_3
+ GROUP BY
+ subq_3.metric_time__day
+ ) subq_4
+ ) subq_5
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_13.metric_time__day
+ , subq_13.bookings AS bookings_2_weeks_ago
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_12.metric_time__day
+ , SUM(subq_12.bookings) AS bookings
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_11.metric_time__day
+ , subq_11.bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_10.metric_time__day
+ , subq_10.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_8.metric_time__day AS metric_time__day
+ , subq_7.ds__day AS ds__day
+ , subq_7.ds__week AS ds__week
+ , subq_7.ds__month AS ds__month
+ , subq_7.ds__quarter AS ds__quarter
+ , subq_7.ds__year AS ds__year
+ , subq_7.ds__extract_year AS ds__extract_year
+ , subq_7.ds__extract_quarter AS ds__extract_quarter
+ , subq_7.ds__extract_month AS ds__extract_month
+ , subq_7.ds__extract_day AS ds__extract_day
+ , subq_7.ds__extract_dow AS ds__extract_dow
+ , subq_7.ds__extract_doy AS ds__extract_doy
+ , subq_7.ds_partitioned__day AS ds_partitioned__day
+ , subq_7.ds_partitioned__week AS ds_partitioned__week
+ , subq_7.ds_partitioned__month AS ds_partitioned__month
+ , subq_7.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_7.ds_partitioned__year AS ds_partitioned__year
+ , subq_7.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_7.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_7.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_7.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_7.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_7.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_7.paid_at__day AS paid_at__day
+ , subq_7.paid_at__week AS paid_at__week
+ , subq_7.paid_at__month AS paid_at__month
+ , subq_7.paid_at__quarter AS paid_at__quarter
+ , subq_7.paid_at__year AS paid_at__year
+ , subq_7.paid_at__extract_year AS paid_at__extract_year
+ , subq_7.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_7.paid_at__extract_month AS paid_at__extract_month
+ , subq_7.paid_at__extract_day AS paid_at__extract_day
+ , subq_7.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_7.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_7.booking__ds__day AS booking__ds__day
+ , subq_7.booking__ds__week AS booking__ds__week
+ , subq_7.booking__ds__month AS booking__ds__month
+ , subq_7.booking__ds__quarter AS booking__ds__quarter
+ , subq_7.booking__ds__year AS booking__ds__year
+ , subq_7.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_7.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_7.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_7.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_7.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_7.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_7.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_7.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_7.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_7.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_7.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_7.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_7.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_7.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_7.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_7.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_7.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_7.booking__paid_at__day AS booking__paid_at__day
+ , subq_7.booking__paid_at__week AS booking__paid_at__week
+ , subq_7.booking__paid_at__month AS booking__paid_at__month
+ , subq_7.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_7.booking__paid_at__year AS booking__paid_at__year
+ , subq_7.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_7.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_7.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_7.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_7.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_7.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_7.listing AS listing
+ , subq_7.guest AS guest
+ , subq_7.host AS host
+ , subq_7.booking__listing AS booking__listing
+ , subq_7.booking__guest AS booking__guest
+ , subq_7.booking__host AS booking__host
+ , subq_7.is_instant AS is_instant
+ , subq_7.booking__is_instant AS booking__is_instant
+ , subq_7.bookings AS bookings
+ , subq_7.instant_bookings AS instant_bookings
+ , subq_7.booking_value AS booking_value
+ , subq_7.max_booking_value AS max_booking_value
+ , subq_7.min_booking_value AS min_booking_value
+ , subq_7.bookers AS bookers
+ , subq_7.average_booking_value AS average_booking_value
+ , subq_7.referred_bookings AS referred_bookings
+ , subq_7.median_booking_value AS median_booking_value
+ , subq_7.booking_value_p99 AS booking_value_p99
+ , subq_7.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_7.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_7.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_9.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_9
+ ) subq_8
+ INNER JOIN (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.ds_partitioned__day
+ , subq_6.ds_partitioned__week
+ , subq_6.ds_partitioned__month
+ , subq_6.ds_partitioned__quarter
+ , subq_6.ds_partitioned__year
+ , subq_6.ds_partitioned__extract_year
+ , subq_6.ds_partitioned__extract_quarter
+ , subq_6.ds_partitioned__extract_month
+ , subq_6.ds_partitioned__extract_day
+ , subq_6.ds_partitioned__extract_dow
+ , subq_6.ds_partitioned__extract_doy
+ , subq_6.paid_at__day
+ , subq_6.paid_at__week
+ , subq_6.paid_at__month
+ , subq_6.paid_at__quarter
+ , subq_6.paid_at__year
+ , subq_6.paid_at__extract_year
+ , subq_6.paid_at__extract_quarter
+ , subq_6.paid_at__extract_month
+ , subq_6.paid_at__extract_day
+ , subq_6.paid_at__extract_dow
+ , subq_6.paid_at__extract_doy
+ , subq_6.booking__ds__day
+ , subq_6.booking__ds__week
+ , subq_6.booking__ds__month
+ , subq_6.booking__ds__quarter
+ , subq_6.booking__ds__year
+ , subq_6.booking__ds__extract_year
+ , subq_6.booking__ds__extract_quarter
+ , subq_6.booking__ds__extract_month
+ , subq_6.booking__ds__extract_day
+ , subq_6.booking__ds__extract_dow
+ , subq_6.booking__ds__extract_doy
+ , subq_6.booking__ds_partitioned__day
+ , subq_6.booking__ds_partitioned__week
+ , subq_6.booking__ds_partitioned__month
+ , subq_6.booking__ds_partitioned__quarter
+ , subq_6.booking__ds_partitioned__year
+ , subq_6.booking__ds_partitioned__extract_year
+ , subq_6.booking__ds_partitioned__extract_quarter
+ , subq_6.booking__ds_partitioned__extract_month
+ , subq_6.booking__ds_partitioned__extract_day
+ , subq_6.booking__ds_partitioned__extract_dow
+ , subq_6.booking__ds_partitioned__extract_doy
+ , subq_6.booking__paid_at__day
+ , subq_6.booking__paid_at__week
+ , subq_6.booking__paid_at__month
+ , subq_6.booking__paid_at__quarter
+ , subq_6.booking__paid_at__year
+ , subq_6.booking__paid_at__extract_year
+ , subq_6.booking__paid_at__extract_quarter
+ , subq_6.booking__paid_at__extract_month
+ , subq_6.booking__paid_at__extract_day
+ , subq_6.booking__paid_at__extract_dow
+ , subq_6.booking__paid_at__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.listing
+ , subq_6.guest
+ , subq_6.host
+ , subq_6.booking__listing
+ , subq_6.booking__guest
+ , subq_6.booking__host
+ , subq_6.is_instant
+ , subq_6.booking__is_instant
+ , subq_6.bookings
+ , subq_6.instant_bookings
+ , subq_6.booking_value
+ , subq_6.max_booking_value
+ , subq_6.min_booking_value
+ , subq_6.bookers
+ , subq_6.average_booking_value
+ , subq_6.referred_bookings
+ , subq_6.median_booking_value
+ , subq_6.booking_value_p99
+ , subq_6.discrete_booking_value_p99
+ , subq_6.approximate_continuous_booking_value_p99
+ , subq_6.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_6
+ ) subq_7
+ ON
+ DATE_ADD('day', -14, subq_8.metric_time__day) = subq_7.metric_time__day
+ ) subq_10
+ ) subq_11
+ WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14'
+ ) subq_12
+ GROUP BY
+ subq_12.metric_time__day
+ ) subq_13
+ ) subq_14
+ ON
+ subq_5.metric_time__day = subq_14.metric_time__day
+ GROUP BY
+ COALESCE(subq_5.metric_time__day, subq_14.metric_time__day)
+) subq_15
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql
new file mode 100644
index 0000000000..d1ff5de63a
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_metric_with_offset_window_and_time_filter__plan0_optimized.sql
@@ -0,0 +1,66 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_21.metric_time__day, subq_30.metric_time__day) AS metric_time__day
+ , MAX(subq_21.bookings) AS bookings
+ , MAX(subq_30.bookings_2_weeks_ago) AS bookings_2_weeks_ago
+ FROM (
+ -- Constrain Output with WHERE
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_18
+ WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14'
+ GROUP BY
+ metric_time__day
+ ) subq_21
+ FULL OUTER JOIN (
+ -- Constrain Output with WHERE
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings_2_weeks_ago
+ FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_25.ds AS metric_time__day
+ , subq_23.bookings AS bookings
+ FROM ***************************.mf_time_spine subq_25
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_23
+ ON
+ DATE_ADD('day', -14, subq_25.ds) = subq_23.metric_time__day
+ ) subq_27
+ WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14'
+ GROUP BY
+ metric_time__day
+ ) subq_30
+ ON
+ subq_21.metric_time__day = subq_30.metric_time__day
+ GROUP BY
+ COALESCE(subq_21.metric_time__day, subq_30.metric_time__day)
+) subq_31
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
new file mode 100644
index 0000000000..cdc607f869
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0.sql
@@ -0,0 +1,434 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_10.metric_time__day
+ , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago
+FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_9.metric_time__day
+ , subq_9.bookers AS every_2_days_bookers_2_days_ago
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_8.metric_time__day
+ , COUNT(DISTINCT subq_8.bookers) AS bookers
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookers', 'metric_time__day']
+ SELECT
+ subq_7.metric_time__day
+ , subq_7.bookers
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_5.metric_time__day AS metric_time__day
+ , subq_4.ds__day AS ds__day
+ , subq_4.ds__week AS ds__week
+ , subq_4.ds__month AS ds__month
+ , subq_4.ds__quarter AS ds__quarter
+ , subq_4.ds__year AS ds__year
+ , subq_4.ds__extract_year AS ds__extract_year
+ , subq_4.ds__extract_quarter AS ds__extract_quarter
+ , subq_4.ds__extract_month AS ds__extract_month
+ , subq_4.ds__extract_day AS ds__extract_day
+ , subq_4.ds__extract_dow AS ds__extract_dow
+ , subq_4.ds__extract_doy AS ds__extract_doy
+ , subq_4.ds_partitioned__day AS ds_partitioned__day
+ , subq_4.ds_partitioned__week AS ds_partitioned__week
+ , subq_4.ds_partitioned__month AS ds_partitioned__month
+ , subq_4.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_4.ds_partitioned__year AS ds_partitioned__year
+ , subq_4.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_4.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_4.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_4.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_4.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_4.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_4.paid_at__day AS paid_at__day
+ , subq_4.paid_at__week AS paid_at__week
+ , subq_4.paid_at__month AS paid_at__month
+ , subq_4.paid_at__quarter AS paid_at__quarter
+ , subq_4.paid_at__year AS paid_at__year
+ , subq_4.paid_at__extract_year AS paid_at__extract_year
+ , subq_4.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_4.paid_at__extract_month AS paid_at__extract_month
+ , subq_4.paid_at__extract_day AS paid_at__extract_day
+ , subq_4.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_4.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_4.booking__ds__day AS booking__ds__day
+ , subq_4.booking__ds__week AS booking__ds__week
+ , subq_4.booking__ds__month AS booking__ds__month
+ , subq_4.booking__ds__quarter AS booking__ds__quarter
+ , subq_4.booking__ds__year AS booking__ds__year
+ , subq_4.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_4.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_4.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_4.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_4.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_4.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_4.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_4.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_4.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_4.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_4.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_4.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_4.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_4.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_4.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_4.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_4.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_4.booking__paid_at__day AS booking__paid_at__day
+ , subq_4.booking__paid_at__week AS booking__paid_at__week
+ , subq_4.booking__paid_at__month AS booking__paid_at__month
+ , subq_4.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_4.booking__paid_at__year AS booking__paid_at__year
+ , subq_4.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_4.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_4.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_4.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_4.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_4.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_4.listing AS listing
+ , subq_4.guest AS guest
+ , subq_4.host AS host
+ , subq_4.booking__listing AS booking__listing
+ , subq_4.booking__guest AS booking__guest
+ , subq_4.booking__host AS booking__host
+ , subq_4.is_instant AS is_instant
+ , subq_4.booking__is_instant AS booking__is_instant
+ , subq_4.bookings AS bookings
+ , subq_4.instant_bookings AS instant_bookings
+ , subq_4.booking_value AS booking_value
+ , subq_4.max_booking_value AS max_booking_value
+ , subq_4.min_booking_value AS min_booking_value
+ , subq_4.bookers AS bookers
+ , subq_4.average_booking_value AS average_booking_value
+ , subq_4.referred_bookings AS referred_bookings
+ , subq_4.median_booking_value AS median_booking_value
+ , subq_4.booking_value_p99 AS booking_value_p99
+ , subq_4.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_4.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_4.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_6.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_6
+ ) subq_5
+ INNER JOIN (
+ -- Join Self Over Time Range
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , 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.metric_time__week AS metric_time__week
+ , subq_1.metric_time__month AS metric_time__month
+ , subq_1.metric_time__quarter AS metric_time__quarter
+ , subq_1.metric_time__year AS metric_time__year
+ , subq_1.metric_time__extract_year AS metric_time__extract_year
+ , subq_1.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_1.metric_time__extract_month AS metric_time__extract_month
+ , subq_1.metric_time__extract_day AS metric_time__extract_day
+ , subq_1.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_1.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_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 (
+ -- Date 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ON
+ (
+ subq_1.metric_time__day <= subq_2.metric_time__day
+ ) AND (
+ subq_1.metric_time__day > DATE_ADD('day', -2, subq_2.metric_time__day)
+ )
+ ) subq_4
+ ON
+ DATE_ADD('day', -2, subq_5.metric_time__day) = subq_4.metric_time__day
+ ) subq_7
+ ) subq_8
+ GROUP BY
+ subq_8.metric_time__day
+ ) subq_9
+) subq_10
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql
new file mode 100644
index 0000000000..9d0f96b918
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_cumulative_metric__plan0_optimized.sql
@@ -0,0 +1,34 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , every_2_days_bookers_2_days_ago AS every_2_days_bookers_2_days_ago
+FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookers', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_17.ds AS metric_time__day
+ , COUNT(DISTINCT subq_15.bookers) AS every_2_days_bookers_2_days_ago
+ FROM ***************************.mf_time_spine subq_17
+ INNER JOIN (
+ -- Join Self Over Time Range
+ SELECT
+ subq_14.ds AS metric_time__day
+ , bookings_source_src_10001.guest_id AS bookers
+ FROM ***************************.mf_time_spine subq_14
+ INNER JOIN
+ ***************************.fct_bookings bookings_source_src_10001
+ ON
+ (
+ DATE_TRUNC('day', bookings_source_src_10001.ds) <= subq_14.ds
+ ) AND (
+ DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_ADD('day', -2, subq_14.ds)
+ )
+ ) subq_15
+ ON
+ DATE_ADD('day', -2, subq_17.ds) = subq_15.metric_time__day
+ GROUP BY
+ subq_17.ds
+) subq_21
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
new file mode 100644
index 0000000000..b6365b4353
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0.sql
@@ -0,0 +1,320 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_7.metric_time__day
+ , bookings_5_days_ago AS bookings_5_day_lag
+FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.bookings AS bookings_5_days_ago
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_5.metric_time__day
+ , SUM(subq_5.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_4.metric_time__day
+ , subq_4.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , 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 (
+ -- Date 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ON
+ DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day
+ ) subq_4
+ ) subq_5
+ GROUP BY
+ subq_5.metric_time__day
+ ) subq_6
+) subq_7
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql
new file mode 100644
index 0000000000..5b1b77974b
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_derived_offset_metric_with_one_input_metric__plan0_optimized.sql
@@ -0,0 +1,27 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , bookings_5_days_ago AS bookings_5_day_lag
+FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_11.ds AS metric_time__day
+ , SUM(subq_9.bookings) AS bookings_5_days_ago
+ FROM ***************************.mf_time_spine subq_11
+ 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_10001
+ ) subq_9
+ ON
+ DATE_ADD('day', -5, subq_11.ds) = subq_9.metric_time__day
+ GROUP BY
+ subq_11.ds
+) subq_15
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql
new file mode 100644
index 0000000000..58d37cfe4c
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0.sql
@@ -0,0 +1,899 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_22.metric_time__day
+ , non_referred + (instant * 1.0 / bookings) AS instant_plus_non_referred_bookings_pct
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_11.metric_time__day, subq_16.metric_time__day, subq_21.metric_time__day) AS metric_time__day
+ , MAX(subq_11.non_referred) AS non_referred
+ , MAX(subq_16.instant) AS instant
+ , MAX(subq_21.bookings) AS bookings
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_10.metric_time__day
+ , (bookings - ref_bookings) * 1.0 / bookings AS non_referred
+ FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day
+ , MAX(subq_4.ref_bookings) AS ref_bookings
+ , MAX(subq_9.bookings) AS bookings
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.referred_bookings AS ref_bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , SUM(subq_2.referred_bookings) AS referred_bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['referred_bookings', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.referred_bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ ) subq_3
+ ) subq_4
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_8.metric_time__day
+ , subq_8.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_7.metric_time__day
+ , SUM(subq_7.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.ds_partitioned__day
+ , subq_5.ds_partitioned__week
+ , subq_5.ds_partitioned__month
+ , subq_5.ds_partitioned__quarter
+ , subq_5.ds_partitioned__year
+ , subq_5.ds_partitioned__extract_year
+ , subq_5.ds_partitioned__extract_quarter
+ , subq_5.ds_partitioned__extract_month
+ , subq_5.ds_partitioned__extract_day
+ , subq_5.ds_partitioned__extract_dow
+ , subq_5.ds_partitioned__extract_doy
+ , subq_5.paid_at__day
+ , subq_5.paid_at__week
+ , subq_5.paid_at__month
+ , subq_5.paid_at__quarter
+ , subq_5.paid_at__year
+ , subq_5.paid_at__extract_year
+ , subq_5.paid_at__extract_quarter
+ , subq_5.paid_at__extract_month
+ , subq_5.paid_at__extract_day
+ , subq_5.paid_at__extract_dow
+ , subq_5.paid_at__extract_doy
+ , subq_5.booking__ds__day
+ , subq_5.booking__ds__week
+ , subq_5.booking__ds__month
+ , subq_5.booking__ds__quarter
+ , subq_5.booking__ds__year
+ , subq_5.booking__ds__extract_year
+ , subq_5.booking__ds__extract_quarter
+ , subq_5.booking__ds__extract_month
+ , subq_5.booking__ds__extract_day
+ , subq_5.booking__ds__extract_dow
+ , subq_5.booking__ds__extract_doy
+ , subq_5.booking__ds_partitioned__day
+ , subq_5.booking__ds_partitioned__week
+ , subq_5.booking__ds_partitioned__month
+ , subq_5.booking__ds_partitioned__quarter
+ , subq_5.booking__ds_partitioned__year
+ , subq_5.booking__ds_partitioned__extract_year
+ , subq_5.booking__ds_partitioned__extract_quarter
+ , subq_5.booking__ds_partitioned__extract_month
+ , subq_5.booking__ds_partitioned__extract_day
+ , subq_5.booking__ds_partitioned__extract_dow
+ , subq_5.booking__ds_partitioned__extract_doy
+ , subq_5.booking__paid_at__day
+ , subq_5.booking__paid_at__week
+ , subq_5.booking__paid_at__month
+ , subq_5.booking__paid_at__quarter
+ , subq_5.booking__paid_at__year
+ , subq_5.booking__paid_at__extract_year
+ , subq_5.booking__paid_at__extract_quarter
+ , subq_5.booking__paid_at__extract_month
+ , subq_5.booking__paid_at__extract_day
+ , subq_5.booking__paid_at__extract_dow
+ , subq_5.booking__paid_at__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.listing
+ , subq_5.guest
+ , subq_5.host
+ , subq_5.booking__listing
+ , subq_5.booking__guest
+ , subq_5.booking__host
+ , subq_5.is_instant
+ , subq_5.booking__is_instant
+ , subq_5.bookings
+ , subq_5.instant_bookings
+ , subq_5.booking_value
+ , subq_5.max_booking_value
+ , subq_5.min_booking_value
+ , subq_5.bookers
+ , subq_5.average_booking_value
+ , subq_5.referred_bookings
+ , subq_5.median_booking_value
+ , subq_5.booking_value_p99
+ , subq_5.discrete_booking_value_p99
+ , subq_5.approximate_continuous_booking_value_p99
+ , subq_5.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_5
+ ) subq_6
+ ) subq_7
+ GROUP BY
+ subq_7.metric_time__day
+ ) subq_8
+ ) subq_9
+ ON
+ subq_4.metric_time__day = subq_9.metric_time__day
+ GROUP BY
+ COALESCE(subq_4.metric_time__day, subq_9.metric_time__day)
+ ) subq_10
+ ) subq_11
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_15.metric_time__day
+ , subq_15.instant_bookings AS instant
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_14.metric_time__day
+ , SUM(subq_14.instant_bookings) AS instant_bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['instant_bookings', 'metric_time__day']
+ SELECT
+ subq_13.metric_time__day
+ , subq_13.instant_bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.ds_partitioned__day
+ , subq_12.ds_partitioned__week
+ , subq_12.ds_partitioned__month
+ , subq_12.ds_partitioned__quarter
+ , subq_12.ds_partitioned__year
+ , subq_12.ds_partitioned__extract_year
+ , subq_12.ds_partitioned__extract_quarter
+ , subq_12.ds_partitioned__extract_month
+ , subq_12.ds_partitioned__extract_day
+ , subq_12.ds_partitioned__extract_dow
+ , subq_12.ds_partitioned__extract_doy
+ , subq_12.paid_at__day
+ , subq_12.paid_at__week
+ , subq_12.paid_at__month
+ , subq_12.paid_at__quarter
+ , subq_12.paid_at__year
+ , subq_12.paid_at__extract_year
+ , subq_12.paid_at__extract_quarter
+ , subq_12.paid_at__extract_month
+ , subq_12.paid_at__extract_day
+ , subq_12.paid_at__extract_dow
+ , subq_12.paid_at__extract_doy
+ , subq_12.booking__ds__day
+ , subq_12.booking__ds__week
+ , subq_12.booking__ds__month
+ , subq_12.booking__ds__quarter
+ , subq_12.booking__ds__year
+ , subq_12.booking__ds__extract_year
+ , subq_12.booking__ds__extract_quarter
+ , subq_12.booking__ds__extract_month
+ , subq_12.booking__ds__extract_day
+ , subq_12.booking__ds__extract_dow
+ , subq_12.booking__ds__extract_doy
+ , subq_12.booking__ds_partitioned__day
+ , subq_12.booking__ds_partitioned__week
+ , subq_12.booking__ds_partitioned__month
+ , subq_12.booking__ds_partitioned__quarter
+ , subq_12.booking__ds_partitioned__year
+ , subq_12.booking__ds_partitioned__extract_year
+ , subq_12.booking__ds_partitioned__extract_quarter
+ , subq_12.booking__ds_partitioned__extract_month
+ , subq_12.booking__ds_partitioned__extract_day
+ , subq_12.booking__ds_partitioned__extract_dow
+ , subq_12.booking__ds_partitioned__extract_doy
+ , subq_12.booking__paid_at__day
+ , subq_12.booking__paid_at__week
+ , subq_12.booking__paid_at__month
+ , subq_12.booking__paid_at__quarter
+ , subq_12.booking__paid_at__year
+ , subq_12.booking__paid_at__extract_year
+ , subq_12.booking__paid_at__extract_quarter
+ , subq_12.booking__paid_at__extract_month
+ , subq_12.booking__paid_at__extract_day
+ , subq_12.booking__paid_at__extract_dow
+ , subq_12.booking__paid_at__extract_doy
+ , subq_12.ds__day AS metric_time__day
+ , subq_12.ds__week AS metric_time__week
+ , subq_12.ds__month AS metric_time__month
+ , subq_12.ds__quarter AS metric_time__quarter
+ , subq_12.ds__year AS metric_time__year
+ , subq_12.ds__extract_year AS metric_time__extract_year
+ , subq_12.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_12.ds__extract_month AS metric_time__extract_month
+ , subq_12.ds__extract_day AS metric_time__extract_day
+ , subq_12.ds__extract_dow AS metric_time__extract_dow
+ , subq_12.ds__extract_doy AS metric_time__extract_doy
+ , subq_12.listing
+ , subq_12.guest
+ , subq_12.host
+ , subq_12.booking__listing
+ , subq_12.booking__guest
+ , subq_12.booking__host
+ , subq_12.is_instant
+ , subq_12.booking__is_instant
+ , subq_12.bookings
+ , subq_12.instant_bookings
+ , subq_12.booking_value
+ , subq_12.max_booking_value
+ , subq_12.min_booking_value
+ , subq_12.bookers
+ , subq_12.average_booking_value
+ , subq_12.referred_bookings
+ , subq_12.median_booking_value
+ , subq_12.booking_value_p99
+ , subq_12.discrete_booking_value_p99
+ , subq_12.approximate_continuous_booking_value_p99
+ , subq_12.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_12
+ ) subq_13
+ ) subq_14
+ GROUP BY
+ subq_14.metric_time__day
+ ) subq_15
+ ) subq_16
+ ON
+ subq_11.metric_time__day = subq_16.metric_time__day
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_20.metric_time__day
+ , subq_20.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_19.metric_time__day
+ , SUM(subq_19.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_18.metric_time__day
+ , subq_18.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_17.ds__day
+ , subq_17.ds__week
+ , subq_17.ds__month
+ , subq_17.ds__quarter
+ , subq_17.ds__year
+ , subq_17.ds__extract_year
+ , subq_17.ds__extract_quarter
+ , subq_17.ds__extract_month
+ , subq_17.ds__extract_day
+ , subq_17.ds__extract_dow
+ , subq_17.ds__extract_doy
+ , subq_17.ds_partitioned__day
+ , subq_17.ds_partitioned__week
+ , subq_17.ds_partitioned__month
+ , subq_17.ds_partitioned__quarter
+ , subq_17.ds_partitioned__year
+ , subq_17.ds_partitioned__extract_year
+ , subq_17.ds_partitioned__extract_quarter
+ , subq_17.ds_partitioned__extract_month
+ , subq_17.ds_partitioned__extract_day
+ , subq_17.ds_partitioned__extract_dow
+ , subq_17.ds_partitioned__extract_doy
+ , subq_17.paid_at__day
+ , subq_17.paid_at__week
+ , subq_17.paid_at__month
+ , subq_17.paid_at__quarter
+ , subq_17.paid_at__year
+ , subq_17.paid_at__extract_year
+ , subq_17.paid_at__extract_quarter
+ , subq_17.paid_at__extract_month
+ , subq_17.paid_at__extract_day
+ , subq_17.paid_at__extract_dow
+ , subq_17.paid_at__extract_doy
+ , subq_17.booking__ds__day
+ , subq_17.booking__ds__week
+ , subq_17.booking__ds__month
+ , subq_17.booking__ds__quarter
+ , subq_17.booking__ds__year
+ , subq_17.booking__ds__extract_year
+ , subq_17.booking__ds__extract_quarter
+ , subq_17.booking__ds__extract_month
+ , subq_17.booking__ds__extract_day
+ , subq_17.booking__ds__extract_dow
+ , subq_17.booking__ds__extract_doy
+ , subq_17.booking__ds_partitioned__day
+ , subq_17.booking__ds_partitioned__week
+ , subq_17.booking__ds_partitioned__month
+ , subq_17.booking__ds_partitioned__quarter
+ , subq_17.booking__ds_partitioned__year
+ , subq_17.booking__ds_partitioned__extract_year
+ , subq_17.booking__ds_partitioned__extract_quarter
+ , subq_17.booking__ds_partitioned__extract_month
+ , subq_17.booking__ds_partitioned__extract_day
+ , subq_17.booking__ds_partitioned__extract_dow
+ , subq_17.booking__ds_partitioned__extract_doy
+ , subq_17.booking__paid_at__day
+ , subq_17.booking__paid_at__week
+ , subq_17.booking__paid_at__month
+ , subq_17.booking__paid_at__quarter
+ , subq_17.booking__paid_at__year
+ , subq_17.booking__paid_at__extract_year
+ , subq_17.booking__paid_at__extract_quarter
+ , subq_17.booking__paid_at__extract_month
+ , subq_17.booking__paid_at__extract_day
+ , subq_17.booking__paid_at__extract_dow
+ , subq_17.booking__paid_at__extract_doy
+ , subq_17.ds__day AS metric_time__day
+ , subq_17.ds__week AS metric_time__week
+ , subq_17.ds__month AS metric_time__month
+ , subq_17.ds__quarter AS metric_time__quarter
+ , subq_17.ds__year AS metric_time__year
+ , subq_17.ds__extract_year AS metric_time__extract_year
+ , subq_17.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_17.ds__extract_month AS metric_time__extract_month
+ , subq_17.ds__extract_day AS metric_time__extract_day
+ , subq_17.ds__extract_dow AS metric_time__extract_dow
+ , subq_17.ds__extract_doy AS metric_time__extract_doy
+ , subq_17.listing
+ , subq_17.guest
+ , subq_17.host
+ , subq_17.booking__listing
+ , subq_17.booking__guest
+ , subq_17.booking__host
+ , subq_17.is_instant
+ , subq_17.booking__is_instant
+ , subq_17.bookings
+ , subq_17.instant_bookings
+ , subq_17.booking_value
+ , subq_17.max_booking_value
+ , subq_17.min_booking_value
+ , subq_17.bookers
+ , subq_17.average_booking_value
+ , subq_17.referred_bookings
+ , subq_17.median_booking_value
+ , subq_17.booking_value_p99
+ , subq_17.discrete_booking_value_p99
+ , subq_17.approximate_continuous_booking_value_p99
+ , subq_17.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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_17
+ ) subq_18
+ ) subq_19
+ GROUP BY
+ subq_19.metric_time__day
+ ) subq_20
+ ) subq_21
+ ON
+ COALESCE(subq_11.metric_time__day, subq_16.metric_time__day) = subq_21.metric_time__day
+ GROUP BY
+ COALESCE(subq_11.metric_time__day, subq_16.metric_time__day, subq_21.metric_time__day)
+) subq_22
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql
new file mode 100644
index 0000000000..97c8543446
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric__plan0_optimized.sql
@@ -0,0 +1,111 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , non_referred + (instant * 1.0 / bookings) AS instant_plus_non_referred_bookings_pct
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_34.metric_time__day, subq_39.metric_time__day, subq_44.metric_time__day) AS metric_time__day
+ , MAX(subq_34.non_referred) AS non_referred
+ , MAX(subq_39.instant) AS instant
+ , MAX(subq_44.bookings) AS bookings
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , (bookings - ref_bookings) * 1.0 / bookings AS non_referred
+ FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_27.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , MAX(subq_27.ref_bookings) AS ref_bookings
+ , MAX(subq_32.bookings) AS bookings
+ FROM (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(referred_bookings) AS ref_bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['referred_bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_25
+ GROUP BY
+ metric_time__day
+ ) subq_27
+ FULL OUTER JOIN (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_30
+ GROUP BY
+ metric_time__day
+ ) subq_32
+ ON
+ subq_27.metric_time__day = subq_32.metric_time__day
+ GROUP BY
+ COALESCE(subq_27.metric_time__day, subq_32.metric_time__day)
+ ) subq_33
+ ) subq_34
+ FULL OUTER JOIN (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(instant_bookings) AS instant
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['instant_bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_37
+ GROUP BY
+ metric_time__day
+ ) subq_39
+ ON
+ subq_34.metric_time__day = subq_39.metric_time__day
+ FULL OUTER JOIN (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_42
+ GROUP BY
+ metric_time__day
+ ) subq_44
+ ON
+ COALESCE(subq_34.metric_time__day, subq_39.metric_time__day) = subq_44.metric_time__day
+ GROUP BY
+ COALESCE(subq_34.metric_time__day, subq_39.metric_time__day, subq_44.metric_time__day)
+) subq_45
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
new file mode 100644
index 0000000000..d02e51891b
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0.sql
@@ -0,0 +1,361 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_13.metric_time__day
+ , 2 * bookings_offset_once AS bookings_offset_twice
+FROM (
+ -- Pass Only Elements:
+ -- ['metric_time__day', 'bookings_offset_once']
+ SELECT
+ subq_12.metric_time__day
+ , subq_12.bookings_offset_once
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_11.metric_time__day
+ , subq_11.booking__is_instant
+ , subq_11.bookings_offset_once
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_9.metric_time__day AS metric_time__day
+ , subq_8.booking__is_instant AS booking__is_instant
+ , subq_8.bookings_offset_once AS bookings_offset_once
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_10.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_10
+ ) subq_9
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_7.metric_time__day
+ , subq_7.booking__is_instant
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.booking__is_instant
+ , subq_6.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_5.metric_time__day
+ , subq_5.booking__is_instant
+ , SUM(subq_5.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__is_instant', 'metric_time__day']
+ SELECT
+ subq_4.metric_time__day
+ , subq_4.booking__is_instant
+ , subq_4.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , 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 (
+ -- Date 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ON
+ DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day
+ ) subq_4
+ ) subq_5
+ GROUP BY
+ subq_5.metric_time__day
+ , subq_5.booking__is_instant
+ ) subq_6
+ ) subq_7
+ ) subq_8
+ ON
+ DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day
+ ) subq_11
+ WHERE booking__is_instant
+ ) subq_12
+) subq_13
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_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql
new file mode 100644
index 0000000000..e949bb12a5
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_offset_with_joined_where_constraint_not_selected__plan0_optimized.sql
@@ -0,0 +1,56 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , 2 * bookings_offset_once AS bookings_offset_twice
+FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements:
+ -- ['metric_time__day', 'bookings_offset_once']
+ SELECT
+ metric_time__day
+ , bookings_offset_once
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_24.ds AS metric_time__day
+ , subq_22.booking__is_instant AS booking__is_instant
+ , subq_22.bookings_offset_once AS bookings_offset_once
+ FROM ***************************.mf_time_spine subq_24
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , booking__is_instant
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__is_instant', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_17.ds AS metric_time__day
+ , subq_15.booking__is_instant AS booking__is_instant
+ , SUM(subq_15.bookings) AS bookings
+ FROM ***************************.mf_time_spine subq_17
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , is_instant AS booking__is_instant
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_15
+ ON
+ DATE_ADD('day', -5, subq_17.ds) = subq_15.metric_time__day
+ GROUP BY
+ subq_17.ds
+ , subq_15.booking__is_instant
+ ) subq_21
+ ) subq_22
+ ON
+ DATE_ADD('day', -2, subq_24.ds) = subq_22.metric_time__day
+ ) subq_25
+ WHERE booking__is_instant
+) subq_27
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql
new file mode 100644
index 0000000000..5fb0085985
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0.sql
@@ -0,0 +1,473 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_15.metric_time__day
+ , booking_fees - booking_fees_start_of_month AS booking_fees_since_start_of_month
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_8.metric_time__day, subq_14.metric_time__day) AS metric_time__day
+ , MAX(subq_8.booking_fees_start_of_month) AS booking_fees_start_of_month
+ , MAX(subq_14.booking_fees) AS booking_fees
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_6.metric_time__day AS metric_time__day
+ , subq_5.booking_fees_start_of_month AS booking_fees_start_of_month
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_7.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_7
+ ) subq_6
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_4.metric_time__day
+ , booking_value * 0.05 AS booking_fees_start_of_month
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.booking_value
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , SUM(subq_2.booking_value) AS booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.booking_value
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ ) subq_3
+ ) subq_4
+ ) subq_5
+ ON
+ DATE_TRUNC('month', subq_6.metric_time__day) = subq_5.metric_time__day
+ ) subq_8
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_13.metric_time__day
+ , booking_value * 0.05 AS booking_fees
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_12.metric_time__day
+ , subq_12.booking_value
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_11.metric_time__day
+ , SUM(subq_11.booking_value) AS booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ SELECT
+ subq_10.metric_time__day
+ , subq_10.booking_value
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_9.ds__day
+ , subq_9.ds__week
+ , subq_9.ds__month
+ , subq_9.ds__quarter
+ , subq_9.ds__year
+ , subq_9.ds__extract_year
+ , subq_9.ds__extract_quarter
+ , subq_9.ds__extract_month
+ , subq_9.ds__extract_day
+ , subq_9.ds__extract_dow
+ , subq_9.ds__extract_doy
+ , subq_9.ds_partitioned__day
+ , subq_9.ds_partitioned__week
+ , subq_9.ds_partitioned__month
+ , subq_9.ds_partitioned__quarter
+ , subq_9.ds_partitioned__year
+ , subq_9.ds_partitioned__extract_year
+ , subq_9.ds_partitioned__extract_quarter
+ , subq_9.ds_partitioned__extract_month
+ , subq_9.ds_partitioned__extract_day
+ , subq_9.ds_partitioned__extract_dow
+ , subq_9.ds_partitioned__extract_doy
+ , subq_9.paid_at__day
+ , subq_9.paid_at__week
+ , subq_9.paid_at__month
+ , subq_9.paid_at__quarter
+ , subq_9.paid_at__year
+ , subq_9.paid_at__extract_year
+ , subq_9.paid_at__extract_quarter
+ , subq_9.paid_at__extract_month
+ , subq_9.paid_at__extract_day
+ , subq_9.paid_at__extract_dow
+ , subq_9.paid_at__extract_doy
+ , subq_9.booking__ds__day
+ , subq_9.booking__ds__week
+ , subq_9.booking__ds__month
+ , subq_9.booking__ds__quarter
+ , subq_9.booking__ds__year
+ , subq_9.booking__ds__extract_year
+ , subq_9.booking__ds__extract_quarter
+ , subq_9.booking__ds__extract_month
+ , subq_9.booking__ds__extract_day
+ , subq_9.booking__ds__extract_dow
+ , subq_9.booking__ds__extract_doy
+ , subq_9.booking__ds_partitioned__day
+ , subq_9.booking__ds_partitioned__week
+ , subq_9.booking__ds_partitioned__month
+ , subq_9.booking__ds_partitioned__quarter
+ , subq_9.booking__ds_partitioned__year
+ , subq_9.booking__ds_partitioned__extract_year
+ , subq_9.booking__ds_partitioned__extract_quarter
+ , subq_9.booking__ds_partitioned__extract_month
+ , subq_9.booking__ds_partitioned__extract_day
+ , subq_9.booking__ds_partitioned__extract_dow
+ , subq_9.booking__ds_partitioned__extract_doy
+ , subq_9.booking__paid_at__day
+ , subq_9.booking__paid_at__week
+ , subq_9.booking__paid_at__month
+ , subq_9.booking__paid_at__quarter
+ , subq_9.booking__paid_at__year
+ , subq_9.booking__paid_at__extract_year
+ , subq_9.booking__paid_at__extract_quarter
+ , subq_9.booking__paid_at__extract_month
+ , subq_9.booking__paid_at__extract_day
+ , subq_9.booking__paid_at__extract_dow
+ , subq_9.booking__paid_at__extract_doy
+ , subq_9.ds__day AS metric_time__day
+ , subq_9.ds__week AS metric_time__week
+ , subq_9.ds__month AS metric_time__month
+ , subq_9.ds__quarter AS metric_time__quarter
+ , subq_9.ds__year AS metric_time__year
+ , subq_9.ds__extract_year AS metric_time__extract_year
+ , subq_9.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_9.ds__extract_month AS metric_time__extract_month
+ , subq_9.ds__extract_day AS metric_time__extract_day
+ , subq_9.ds__extract_dow AS metric_time__extract_dow
+ , subq_9.ds__extract_doy AS metric_time__extract_doy
+ , subq_9.listing
+ , subq_9.guest
+ , subq_9.host
+ , subq_9.booking__listing
+ , subq_9.booking__guest
+ , subq_9.booking__host
+ , subq_9.is_instant
+ , subq_9.booking__is_instant
+ , subq_9.bookings
+ , subq_9.instant_bookings
+ , subq_9.booking_value
+ , subq_9.max_booking_value
+ , subq_9.min_booking_value
+ , subq_9.bookers
+ , subq_9.average_booking_value
+ , subq_9.referred_bookings
+ , subq_9.median_booking_value
+ , subq_9.booking_value_p99
+ , subq_9.discrete_booking_value_p99
+ , subq_9.approximate_continuous_booking_value_p99
+ , subq_9.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_9
+ ) subq_10
+ ) subq_11
+ GROUP BY
+ subq_11.metric_time__day
+ ) subq_12
+ ) subq_13
+ ) subq_14
+ ON
+ subq_8.metric_time__day = subq_14.metric_time__day
+ GROUP BY
+ COALESCE(subq_8.metric_time__day, subq_14.metric_time__day)
+) subq_15
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql
new file mode 100644
index 0000000000..d26294499f
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_derived_metric_with_offset_multiple_input_metrics__plan0_optimized.sql
@@ -0,0 +1,64 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , booking_fees - booking_fees_start_of_month AS booking_fees_since_start_of_month
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_24.metric_time__day, subq_30.metric_time__day) AS metric_time__day
+ , MAX(subq_24.booking_fees_start_of_month) AS booking_fees_start_of_month
+ , MAX(subq_30.booking_fees) AS booking_fees
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_23.ds AS metric_time__day
+ , subq_21.booking_fees_start_of_month AS booking_fees_start_of_month
+ FROM ***************************.mf_time_spine subq_23
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , booking_value * 0.05 AS booking_fees_start_of_month
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , SUM(booking_value) AS booking_value
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ GROUP BY
+ DATE_TRUNC('day', ds)
+ ) subq_20
+ ) subq_21
+ ON
+ DATE_TRUNC('month', subq_23.ds) = subq_21.metric_time__day
+ ) subq_24
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , booking_value * 0.05 AS booking_fees
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , SUM(booking_value) AS booking_value
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ GROUP BY
+ DATE_TRUNC('day', ds)
+ ) subq_29
+ ) subq_30
+ ON
+ subq_24.metric_time__day = subq_30.metric_time__day
+ GROUP BY
+ COALESCE(subq_24.metric_time__day, subq_30.metric_time__day)
+) subq_31
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
new file mode 100644
index 0000000000..9dd2d000cc
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0.sql
@@ -0,0 +1,340 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_11.metric_time__day
+ , 2 * bookings_offset_once AS bookings_offset_twice
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_9.metric_time__day AS metric_time__day
+ , subq_8.bookings_offset_once AS bookings_offset_once
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_10.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_10
+ ) subq_9
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_7.metric_time__day
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_5.metric_time__day
+ , SUM(subq_5.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_4.metric_time__day
+ , subq_4.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , 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 (
+ -- Date 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ON
+ DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day
+ ) subq_4
+ ) subq_5
+ GROUP BY
+ subq_5.metric_time__day
+ ) subq_6
+ ) subq_7
+ ) subq_8
+ ON
+ DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day
+) subq_11
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql
new file mode 100644
index 0000000000..9b5674304c
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets__plan0_optimized.sql
@@ -0,0 +1,42 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , 2 * bookings_offset_once AS bookings_offset_twice
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_22.ds AS metric_time__day
+ , subq_20.bookings_offset_once AS bookings_offset_once
+ FROM ***************************.mf_time_spine subq_22
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_15.ds AS metric_time__day
+ , SUM(subq_13.bookings) AS bookings
+ FROM ***************************.mf_time_spine subq_15
+ 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_10001
+ ) subq_13
+ ON
+ DATE_ADD('day', -5, subq_15.ds) = subq_13.metric_time__day
+ GROUP BY
+ subq_15.ds
+ ) subq_19
+ ) subq_20
+ ON
+ DATE_ADD('day', -2, subq_22.ds) = subq_20.metric_time__day
+) subq_23
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
new file mode 100644
index 0000000000..e9543a2a73
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0.sql
@@ -0,0 +1,341 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_11.metric_time__day
+ , 2 * bookings_offset_once AS bookings_offset_twice
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_9.metric_time__day AS metric_time__day
+ , subq_8.bookings_offset_once AS bookings_offset_once
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_10.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_10
+ WHERE subq_10.ds BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13'
+ ) subq_9
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_7.metric_time__day
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_5.metric_time__day
+ , SUM(subq_5.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_4.metric_time__day
+ , subq_4.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , 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 (
+ -- Date 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ON
+ DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day
+ ) subq_4
+ ) subq_5
+ GROUP BY
+ subq_5.metric_time__day
+ ) subq_6
+ ) subq_7
+ ) subq_8
+ ON
+ DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day
+) subq_11
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql
new file mode 100644
index 0000000000..e00400a25b
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_time_constraint__plan0_optimized.sql
@@ -0,0 +1,48 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , 2 * bookings_offset_once AS bookings_offset_twice
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_21.metric_time__day AS metric_time__day
+ , subq_20.bookings_offset_once AS bookings_offset_once
+ FROM (
+ -- Date Spine
+ SELECT
+ ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_22
+ WHERE ds BETWEEN timestamp '2020-01-12' AND timestamp '2020-01-13'
+ ) subq_21
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_15.ds AS metric_time__day
+ , SUM(subq_13.bookings) AS bookings
+ FROM ***************************.mf_time_spine subq_15
+ 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_10001
+ ) subq_13
+ ON
+ DATE_ADD('day', -5, subq_15.ds) = subq_13.metric_time__day
+ GROUP BY
+ subq_15.ds
+ ) subq_19
+ ) subq_20
+ ON
+ DATE_ADD('day', -2, subq_21.metric_time__day) = subq_20.metric_time__day
+) subq_23
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
new file mode 100644
index 0000000000..39198ed5f4
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0.sql
@@ -0,0 +1,347 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_12.metric_time__day
+ , 2 * bookings_offset_once AS bookings_offset_twice
+FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_11.metric_time__day
+ , subq_11.bookings_offset_once
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_9.metric_time__day AS metric_time__day
+ , subq_8.bookings_offset_once AS bookings_offset_once
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_10.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_10
+ ) subq_9
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_7.metric_time__day
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_5.metric_time__day
+ , SUM(subq_5.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_4.metric_time__day
+ , subq_4.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , 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 (
+ -- Date 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ON
+ DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day
+ ) subq_4
+ ) subq_5
+ GROUP BY
+ subq_5.metric_time__day
+ ) subq_6
+ ) subq_7
+ ) subq_8
+ ON
+ DATE_ADD('day', -2, subq_9.metric_time__day) = subq_8.metric_time__day
+ ) subq_11
+ WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13'
+) subq_12
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql
new file mode 100644
index 0000000000..a594f89255
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_nested_offsets_with_where_constraint__plan0_optimized.sql
@@ -0,0 +1,49 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , 2 * bookings_offset_once AS bookings_offset_twice
+FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ metric_time__day
+ , bookings_offset_once
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_23.ds AS metric_time__day
+ , subq_21.bookings_offset_once AS bookings_offset_once
+ FROM ***************************.mf_time_spine subq_23
+ INNER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , 2 * bookings AS bookings_offset_once
+ FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_16.ds AS metric_time__day
+ , SUM(subq_14.bookings) AS bookings
+ FROM ***************************.mf_time_spine subq_16
+ INNER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_14
+ ON
+ DATE_ADD('day', -5, subq_16.ds) = subq_14.metric_time__day
+ GROUP BY
+ subq_16.ds
+ ) subq_20
+ ) subq_21
+ ON
+ DATE_ADD('day', -2, subq_23.ds) = subq_21.metric_time__day
+ ) subq_24
+ WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13'
+) subq_25
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
new file mode 100644
index 0000000000..3512e061f0
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0.sql
@@ -0,0 +1,321 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_7.metric_time__day
+ , bookings_5_days_ago AS bookings_5_day_lag
+FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.bookings AS bookings_5_days_ago
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_5.metric_time__day
+ , SUM(subq_5.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_4.metric_time__day
+ , subq_4.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , 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 (
+ -- Date Spine
+ SELECT
+ subq_3.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_3
+ WHERE subq_3.ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02'
+ ) 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ON
+ DATE_ADD('day', -5, subq_2.metric_time__day) = subq_1.metric_time__day
+ ) subq_4
+ ) subq_5
+ GROUP BY
+ subq_5.metric_time__day
+ ) subq_6
+) subq_7
diff --git a/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql
new file mode 100644
index 0000000000..0473434ea6
--- /dev/null
+++ b/metricflow/test/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/Trino/test_time_offset_metric_with_time_constraint__plan0_optimized.sql
@@ -0,0 +1,33 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , bookings_5_days_ago AS bookings_5_day_lag
+FROM (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_10.metric_time__day AS metric_time__day
+ , SUM(subq_9.bookings) AS bookings_5_days_ago
+ FROM (
+ -- Date Spine
+ SELECT
+ ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_11
+ WHERE ds BETWEEN timestamp '2019-12-19' AND timestamp '2020-01-02'
+ ) subq_10
+ 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_10001
+ ) subq_9
+ ON
+ DATE_ADD('day', -5, subq_10.metric_time__day) = subq_9.metric_time__day
+ GROUP BY
+ subq_10.metric_time__day
+) subq_15
diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0.sql
new file mode 100644
index 0000000000..6442c922a7
--- /dev/null
+++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0.sql
@@ -0,0 +1,231 @@
+-- Pass Only Elements:
+-- ['user__home_state_latest', 'listing__is_lux_latest']
+SELECT
+ subq_4.listing__is_lux_latest
+ , subq_4.user__home_state_latest
+FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_3.ds__day
+ , subq_3.ds__week
+ , subq_3.ds__month
+ , subq_3.ds__quarter
+ , subq_3.ds__year
+ , subq_3.ds__extract_year
+ , subq_3.ds__extract_quarter
+ , subq_3.ds__extract_month
+ , subq_3.ds__extract_day
+ , subq_3.ds__extract_dow
+ , subq_3.ds__extract_doy
+ , subq_3.created_at__day
+ , subq_3.created_at__week
+ , subq_3.created_at__month
+ , subq_3.created_at__quarter
+ , subq_3.created_at__year
+ , subq_3.created_at__extract_year
+ , subq_3.created_at__extract_quarter
+ , subq_3.created_at__extract_month
+ , subq_3.created_at__extract_day
+ , subq_3.created_at__extract_dow
+ , subq_3.created_at__extract_doy
+ , subq_3.listing__ds__day
+ , subq_3.listing__ds__week
+ , subq_3.listing__ds__month
+ , subq_3.listing__ds__quarter
+ , subq_3.listing__ds__year
+ , subq_3.listing__ds__extract_year
+ , subq_3.listing__ds__extract_quarter
+ , subq_3.listing__ds__extract_month
+ , subq_3.listing__ds__extract_day
+ , subq_3.listing__ds__extract_dow
+ , subq_3.listing__ds__extract_doy
+ , subq_3.listing__created_at__day
+ , subq_3.listing__created_at__week
+ , subq_3.listing__created_at__month
+ , subq_3.listing__created_at__quarter
+ , subq_3.listing__created_at__year
+ , subq_3.listing__created_at__extract_year
+ , subq_3.listing__created_at__extract_quarter
+ , subq_3.listing__created_at__extract_month
+ , subq_3.listing__created_at__extract_day
+ , subq_3.listing__created_at__extract_dow
+ , subq_3.listing__created_at__extract_doy
+ , subq_3.listing
+ , subq_3.user
+ , subq_3.listing__user
+ , subq_3.country_latest
+ , subq_3.is_lux_latest
+ , subq_3.capacity_latest
+ , subq_3.listing__country_latest
+ , subq_3.listing__is_lux_latest
+ , subq_3.listing__capacity_latest
+ , subq_3.user__home_state_latest
+ , subq_3.listings
+ , subq_3.largest_listing
+ , subq_3.smallest_listing
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_0.ds__day AS ds__day
+ , subq_0.ds__week AS ds__week
+ , subq_0.ds__month AS ds__month
+ , subq_0.ds__quarter AS ds__quarter
+ , subq_0.ds__year AS ds__year
+ , subq_0.ds__extract_year AS ds__extract_year
+ , subq_0.ds__extract_quarter AS ds__extract_quarter
+ , subq_0.ds__extract_month AS ds__extract_month
+ , subq_0.ds__extract_day AS ds__extract_day
+ , subq_0.ds__extract_dow AS ds__extract_dow
+ , subq_0.ds__extract_doy AS ds__extract_doy
+ , subq_0.created_at__day AS created_at__day
+ , subq_0.created_at__week AS created_at__week
+ , subq_0.created_at__month AS created_at__month
+ , subq_0.created_at__quarter AS created_at__quarter
+ , subq_0.created_at__year AS created_at__year
+ , subq_0.created_at__extract_year AS created_at__extract_year
+ , subq_0.created_at__extract_quarter AS created_at__extract_quarter
+ , subq_0.created_at__extract_month AS created_at__extract_month
+ , subq_0.created_at__extract_day AS created_at__extract_day
+ , subq_0.created_at__extract_dow AS created_at__extract_dow
+ , subq_0.created_at__extract_doy AS created_at__extract_doy
+ , subq_0.listing__ds__day AS listing__ds__day
+ , subq_0.listing__ds__week AS listing__ds__week
+ , subq_0.listing__ds__month AS listing__ds__month
+ , subq_0.listing__ds__quarter AS listing__ds__quarter
+ , subq_0.listing__ds__year AS listing__ds__year
+ , subq_0.listing__ds__extract_year AS listing__ds__extract_year
+ , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter
+ , subq_0.listing__ds__extract_month AS listing__ds__extract_month
+ , subq_0.listing__ds__extract_day AS listing__ds__extract_day
+ , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow
+ , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy
+ , subq_0.listing__created_at__day AS listing__created_at__day
+ , subq_0.listing__created_at__week AS listing__created_at__week
+ , subq_0.listing__created_at__month AS listing__created_at__month
+ , subq_0.listing__created_at__quarter AS listing__created_at__quarter
+ , subq_0.listing__created_at__year AS listing__created_at__year
+ , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year
+ , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter
+ , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month
+ , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day
+ , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow
+ , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy
+ , subq_0.listing AS listing
+ , subq_0.user AS user
+ , subq_0.listing__user AS listing__user
+ , subq_0.country_latest AS country_latest
+ , subq_0.is_lux_latest AS is_lux_latest
+ , subq_0.capacity_latest AS capacity_latest
+ , subq_0.listing__country_latest AS listing__country_latest
+ , subq_0.listing__is_lux_latest AS listing__is_lux_latest
+ , subq_0.listing__capacity_latest AS listing__capacity_latest
+ , subq_2.home_state_latest AS user__home_state_latest
+ , subq_0.listings AS listings
+ , subq_0.largest_listing AS largest_listing
+ , subq_0.smallest_listing AS smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_0
+ FULL OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['home_state_latest', 'user']
+ SELECT
+ subq_1.user
+ , subq_1.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_10009.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_10009.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_10009.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_10009.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_10009.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10009.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10009.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_10009.ds) AS ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10009.ds) AS ds_latest__extract_doy
+ , users_latest_src_10009.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_10009.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_10009.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_10009.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_10009.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_10009.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10009.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10009.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_10009.ds) AS user__ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10009.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_10009.home_state_latest AS user__home_state_latest
+ , users_latest_src_10009.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_10009
+ ) subq_1
+ ) subq_2
+ ON
+ subq_0.user = subq_2.user
+ ) subq_3
+ WHERE user__home_state_latest = 'us'
+) subq_4
+GROUP BY
+ subq_4.listing__is_lux_latest
+ , subq_4.user__home_state_latest
diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql
new file mode 100644
index 0000000000..533b86774d
--- /dev/null
+++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql
@@ -0,0 +1,21 @@
+-- Constrain Output with WHERE
+-- Pass Only Elements:
+-- ['user__home_state_latest', 'listing__is_lux_latest']
+SELECT
+ listing__is_lux_latest
+ , user__home_state_latest
+FROM (
+ -- Join Standard Outputs
+ SELECT
+ listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , users_latest_src_10009.home_state_latest AS user__home_state_latest
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ FULL OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_10009
+ ON
+ listings_latest_src_10005.user_id = users_latest_src_10009.user_id
+) subq_8
+WHERE user__home_state_latest = 'us'
+GROUP BY
+ listing__is_lux_latest
+ , user__home_state_latest
diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql
new file mode 100644
index 0000000000..77f81a9548
--- /dev/null
+++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0.sql
@@ -0,0 +1,169 @@
+-- Pass Only Elements:
+-- ['user__home_state_latest', 'listing__is_lux_latest']
+SELECT
+ subq_3.listing__is_lux_latest
+ , subq_3.user__home_state_latest
+FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_0.ds__day AS ds__day
+ , subq_0.ds__week AS ds__week
+ , subq_0.ds__month AS ds__month
+ , subq_0.ds__quarter AS ds__quarter
+ , subq_0.ds__year AS ds__year
+ , subq_0.ds__extract_year AS ds__extract_year
+ , subq_0.ds__extract_quarter AS ds__extract_quarter
+ , subq_0.ds__extract_month AS ds__extract_month
+ , subq_0.ds__extract_day AS ds__extract_day
+ , subq_0.ds__extract_dow AS ds__extract_dow
+ , subq_0.ds__extract_doy AS ds__extract_doy
+ , subq_0.created_at__day AS created_at__day
+ , subq_0.created_at__week AS created_at__week
+ , subq_0.created_at__month AS created_at__month
+ , subq_0.created_at__quarter AS created_at__quarter
+ , subq_0.created_at__year AS created_at__year
+ , subq_0.created_at__extract_year AS created_at__extract_year
+ , subq_0.created_at__extract_quarter AS created_at__extract_quarter
+ , subq_0.created_at__extract_month AS created_at__extract_month
+ , subq_0.created_at__extract_day AS created_at__extract_day
+ , subq_0.created_at__extract_dow AS created_at__extract_dow
+ , subq_0.created_at__extract_doy AS created_at__extract_doy
+ , subq_0.listing__ds__day AS listing__ds__day
+ , subq_0.listing__ds__week AS listing__ds__week
+ , subq_0.listing__ds__month AS listing__ds__month
+ , subq_0.listing__ds__quarter AS listing__ds__quarter
+ , subq_0.listing__ds__year AS listing__ds__year
+ , subq_0.listing__ds__extract_year AS listing__ds__extract_year
+ , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter
+ , subq_0.listing__ds__extract_month AS listing__ds__extract_month
+ , subq_0.listing__ds__extract_day AS listing__ds__extract_day
+ , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow
+ , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy
+ , subq_0.listing__created_at__day AS listing__created_at__day
+ , subq_0.listing__created_at__week AS listing__created_at__week
+ , subq_0.listing__created_at__month AS listing__created_at__month
+ , subq_0.listing__created_at__quarter AS listing__created_at__quarter
+ , subq_0.listing__created_at__year AS listing__created_at__year
+ , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year
+ , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter
+ , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month
+ , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day
+ , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow
+ , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy
+ , subq_0.listing AS listing
+ , subq_0.user AS user
+ , subq_0.listing__user AS listing__user
+ , subq_0.country_latest AS country_latest
+ , subq_0.is_lux_latest AS is_lux_latest
+ , subq_0.capacity_latest AS capacity_latest
+ , subq_0.listing__country_latest AS listing__country_latest
+ , subq_0.listing__is_lux_latest AS listing__is_lux_latest
+ , subq_0.listing__capacity_latest AS listing__capacity_latest
+ , subq_2.home_state_latest AS user__home_state_latest
+ , subq_0.listings AS listings
+ , subq_0.largest_listing AS largest_listing
+ , subq_0.smallest_listing AS smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_0
+ FULL OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['home_state_latest', 'user']
+ SELECT
+ subq_1.user
+ , subq_1.home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_10009.ds) AS ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_10009.ds) AS ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_10009.ds) AS ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_10009.ds) AS ds_latest__year
+ , EXTRACT(year FROM users_latest_src_10009.ds) AS ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10009.ds) AS ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10009.ds) AS ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_10009.ds) AS ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10009.ds) AS ds_latest__extract_doy
+ , users_latest_src_10009.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_10009.ds) AS user__ds_latest__day
+ , DATE_TRUNC('week', users_latest_src_10009.ds) AS user__ds_latest__week
+ , DATE_TRUNC('month', users_latest_src_10009.ds) AS user__ds_latest__month
+ , DATE_TRUNC('quarter', users_latest_src_10009.ds) AS user__ds_latest__quarter
+ , DATE_TRUNC('year', users_latest_src_10009.ds) AS user__ds_latest__year
+ , EXTRACT(year FROM users_latest_src_10009.ds) AS user__ds_latest__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10009.ds) AS user__ds_latest__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10009.ds) AS user__ds_latest__extract_month
+ , EXTRACT(day FROM users_latest_src_10009.ds) AS user__ds_latest__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10009.ds) AS user__ds_latest__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10009.ds) AS user__ds_latest__extract_doy
+ , users_latest_src_10009.home_state_latest AS user__home_state_latest
+ , users_latest_src_10009.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_10009
+ ) subq_1
+ ) subq_2
+ ON
+ subq_0.user = subq_2.user
+) subq_3
+GROUP BY
+ subq_3.listing__is_lux_latest
+ , subq_3.user__home_state_latest
diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql
new file mode 100644
index 0000000000..7f093b6070
--- /dev/null
+++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Trino/test_dimensions_requiring_join__plan0_optimized.sql
@@ -0,0 +1,14 @@
+-- Join Standard Outputs
+-- Pass Only Elements:
+-- ['user__home_state_latest', 'listing__is_lux_latest']
+SELECT
+ listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , users_latest_src_10009.home_state_latest AS user__home_state_latest
+FROM ***************************.dim_listings_latest listings_latest_src_10005
+FULL OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_10009
+ON
+ listings_latest_src_10005.user_id = users_latest_src_10009.user_id
+GROUP BY
+ listings_latest_src_10005.is_lux
+ , users_latest_src_10009.home_state_latest
diff --git a/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_approximate_continuous_percentile_expr__plan0.sql b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_approximate_continuous_percentile_expr__plan0.sql
new file mode 100644
index 0000000000..5ad435c9e1
--- /dev/null
+++ b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_approximate_continuous_percentile_expr__plan0.sql
@@ -0,0 +1,4 @@
+-- Test Approximate Continuous Percentile Expression
+SELECT
+ approx_percentile(a.col0, 0.5) AS col0_percentile
+FROM foo.bar a
diff --git a/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_cast_to_timestamp__plan0.sql b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_cast_to_timestamp__plan0.sql
new file mode 100644
index 0000000000..c47396730d
--- /dev/null
+++ b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_cast_to_timestamp__plan0.sql
@@ -0,0 +1,4 @@
+-- Test Cast to Timestamp Expression
+SELECT
+ CAST('2020-01-01' AS TIMESTAMP) AS col0
+FROM foo.bar a
diff --git a/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_generate_uuid__plan0.sql b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_generate_uuid__plan0.sql
new file mode 100644
index 0000000000..ccdd1213e8
--- /dev/null
+++ b/metricflow/test/snapshots/test_engine_specific_rendering.py/SqlQueryPlan/Trino/test_generate_uuid__plan0.sql
@@ -0,0 +1,4 @@
+-- Test Generate UUID Expression
+SELECT
+ uuid() AS uuid
+FROM foo.bar a
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_fill_nulls_with_0_multi_metric_query__query_output.txt b/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_fill_nulls_with_0_multi_metric_query__query_output.txt
new file mode 100644
index 0000000000..15d152a963
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_fill_nulls_with_0_multi_metric_query__query_output.txt
@@ -0,0 +1,41 @@
+ metric_time__day bookings_fill_nulls_with_0 views
+0 2019-11-27 0 NaN
+1 2019-11-28 0 NaN
+2 2019-11-29 0 NaN
+3 2019-11-30 0 NaN
+4 2019-12-01 1 NaN
+5 2019-12-02 0 NaN
+6 2019-12-03 0 NaN
+7 2019-12-04 0 NaN
+8 2019-12-05 0 NaN
+9 2019-12-06 0 NaN
+10 2019-12-07 0 NaN
+11 2019-12-08 0 NaN
+12 2019-12-09 0 NaN
+13 2019-12-10 0 NaN
+14 2019-12-11 0 NaN
+15 2019-12-12 0 NaN
+16 2019-12-13 0 NaN
+17 2019-12-14 0 NaN
+18 2019-12-15 0 NaN
+19 2019-12-16 0 NaN
+20 2019-12-17 0 NaN
+21 2019-12-18 10 NaN
+22 2019-12-19 18 NaN
+23 2019-12-20 2 NaN
+24 2019-12-21 0 NaN
+25 2019-12-22 0 NaN
+26 2019-12-23 0 NaN
+27 2019-12-24 0 NaN
+28 2019-12-25 0 NaN
+29 2019-12-26 0 NaN
+30 2019-12-27 0 NaN
+31 2019-12-28 0 NaN
+32 2019-12-29 0 NaN
+33 2019-12-30 0 NaN
+34 2019-12-31 0 NaN
+35 2020-01-01 5 2.0
+36 2020-01-02 9 5.0
+37 2020-01-03 1 NaN
+38 2020-01-04 0 1.0
+39 2020-01-05 0 1.0
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_fill_nulls_with_0_multi_metric_query_with_categorical_dimension__query_output.txt b/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_fill_nulls_with_0_multi_metric_query_with_categorical_dimension__query_output.txt
new file mode 100644
index 0000000000..f5bb2ed4ba
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_fill_nulls_with_0_multi_metric_query_with_categorical_dimension__query_output.txt
@@ -0,0 +1,16 @@
+ metric_time__day listing__is_lux_latest bookings_fill_nulls_with_0_without_time_spine views
+0 2019-12-01 True 1 NaN
+1 2019-12-18 False 4 NaN
+2 2019-12-18 True 6 NaN
+3 2019-12-19 False 6 NaN
+4 2019-12-19 True 6 NaN
+5 2019-12-19 None 6 NaN
+6 2019-12-20 True 2 NaN
+7 2020-01-01 False 2 NaN
+8 2020-01-01 True 3 2.0
+9 2020-01-02 False 3 3.0
+10 2020-01-02 True 3 1.0
+11 2020-01-02 None 3 1.0
+12 2020-01-03 True 1 NaN
+13 2020-01-04 False 0 1.0
+14 2020-01-05 None 0 1.0
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_simple_fill_nulls_with_0_metric_time__query_output.txt b/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_simple_fill_nulls_with_0_metric_time__query_output.txt
new file mode 100644
index 0000000000..7a4726bf18
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_simple_fill_nulls_with_0_metric_time__query_output.txt
@@ -0,0 +1,41 @@
+ metric_time__day bookings_fill_nulls_with_0
+0 2019-11-27 0
+1 2019-11-28 0
+2 2019-11-29 0
+3 2019-11-30 0
+4 2019-12-01 1
+5 2019-12-02 0
+6 2019-12-03 0
+7 2019-12-04 0
+8 2019-12-05 0
+9 2019-12-06 0
+10 2019-12-07 0
+11 2019-12-08 0
+12 2019-12-09 0
+13 2019-12-10 0
+14 2019-12-11 0
+15 2019-12-12 0
+16 2019-12-13 0
+17 2019-12-14 0
+18 2019-12-15 0
+19 2019-12-16 0
+20 2019-12-17 0
+21 2019-12-18 10
+22 2019-12-19 18
+23 2019-12-20 2
+24 2019-12-21 0
+25 2019-12-22 0
+26 2019-12-23 0
+27 2019-12-24 0
+28 2019-12-25 0
+29 2019-12-26 0
+30 2019-12-27 0
+31 2019-12-28 0
+32 2019-12-29 0
+33 2019-12-30 0
+34 2019-12-31 0
+35 2020-01-01 5
+36 2020-01-02 9
+37 2020-01-03 1
+38 2020-01-04 0
+39 2020-01-05 0
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_simple_fill_nulls_with_0_month__query_output.txt b/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_simple_fill_nulls_with_0_month__query_output.txt
new file mode 100644
index 0000000000..7ddd9fa0ea
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_simple_fill_nulls_with_0_month__query_output.txt
@@ -0,0 +1,25 @@
+ metric_time__month bookings_fill_nulls_with_0
+0 2019-01-01 0
+1 2019-02-01 0
+2 2019-03-01 0
+3 2019-04-01 0
+4 2019-05-01 0
+5 2019-06-01 0
+6 2019-07-01 0
+7 2019-08-01 0
+8 2019-09-01 0
+9 2019-10-01 0
+10 2019-11-01 0
+11 2019-12-01 31
+12 2020-01-01 15
+13 2020-02-01 0
+14 2020-03-01 0
+15 2020-04-01 0
+16 2020-05-01 0
+17 2020-06-01 0
+18 2020-07-01 0
+19 2020-08-01 0
+20 2020-09-01 0
+21 2020-10-01 0
+22 2020-11-01 0
+23 2020-12-01 0
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_simple_join_to_time_spine__query_output.txt b/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_simple_join_to_time_spine__query_output.txt
new file mode 100644
index 0000000000..2a91746dc1
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_0.py/str/Trino/test_simple_join_to_time_spine__query_output.txt
@@ -0,0 +1,41 @@
+ metric_time__day bookings_join_to_time_spine
+0 2019-11-27 NaN
+1 2019-11-28 NaN
+2 2019-11-29 NaN
+3 2019-11-30 NaN
+4 2019-12-01 1.0
+5 2019-12-02 NaN
+6 2019-12-03 NaN
+7 2019-12-04 NaN
+8 2019-12-05 NaN
+9 2019-12-06 NaN
+10 2019-12-07 NaN
+11 2019-12-08 NaN
+12 2019-12-09 NaN
+13 2019-12-10 NaN
+14 2019-12-11 NaN
+15 2019-12-12 NaN
+16 2019-12-13 NaN
+17 2019-12-14 NaN
+18 2019-12-15 NaN
+19 2019-12-16 NaN
+20 2019-12-17 NaN
+21 2019-12-18 10.0
+22 2019-12-19 18.0
+23 2019-12-20 2.0
+24 2019-12-21 NaN
+25 2019-12-22 NaN
+26 2019-12-23 NaN
+27 2019-12-24 NaN
+28 2019-12-25 NaN
+29 2019-12-26 NaN
+30 2019-12-27 NaN
+31 2019-12-28 NaN
+32 2019-12-29 NaN
+33 2019-12-30 NaN
+34 2019-12-31 NaN
+35 2020-01-01 5.0
+36 2020-01-02 9.0
+37 2020-01-03 1.0
+38 2020-01-04 NaN
+39 2020-01-05 NaN
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql
new file mode 100644
index 0000000000..69b679c136
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0.sql
@@ -0,0 +1,342 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_9.metric_time__day
+ , COALESCE(subq_9.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_7.metric_time__day AS metric_time__day
+ , subq_6.bookers AS bookers
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_8.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_8
+ ) subq_7
+ LEFT OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ subq_5.metric_time__day
+ , COUNT(DISTINCT subq_5.bookers) AS bookers
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookers', 'metric_time__day']
+ SELECT
+ subq_4.metric_time__day
+ , subq_4.bookers
+ FROM (
+ -- Join Self Over Time Range
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , 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.metric_time__week AS metric_time__week
+ , subq_1.metric_time__month AS metric_time__month
+ , subq_1.metric_time__quarter AS metric_time__quarter
+ , subq_1.metric_time__year AS metric_time__year
+ , subq_1.metric_time__extract_year AS metric_time__extract_year
+ , subq_1.metric_time__extract_quarter AS metric_time__extract_quarter
+ , subq_1.metric_time__extract_month AS metric_time__extract_month
+ , subq_1.metric_time__extract_day AS metric_time__extract_day
+ , subq_1.metric_time__extract_dow AS metric_time__extract_dow
+ , subq_1.metric_time__extract_doy AS metric_time__extract_doy
+ , subq_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 (
+ -- Date 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ON
+ (
+ subq_1.metric_time__day <= subq_2.metric_time__day
+ ) AND (
+ subq_1.metric_time__day > DATE_ADD('day', -2, subq_2.metric_time__day)
+ )
+ ) subq_4
+ ) subq_5
+ GROUP BY
+ subq_5.metric_time__day
+ ) subq_6
+ ON
+ subq_7.metric_time__day = subq_6.metric_time__day
+) subq_9
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql
new file mode 100644
index 0000000000..46495e1c9e
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_cumulative_fill_nulls__plan0_optimized.sql
@@ -0,0 +1,33 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , COALESCE(bookers, 0) AS every_two_days_bookers_fill_nulls_with_0
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_18.ds AS metric_time__day
+ , subq_16.bookers AS bookers
+ FROM ***************************.mf_time_spine subq_18
+ LEFT OUTER JOIN (
+ -- Join Self Over Time Range
+ -- Pass Only Elements:
+ -- ['bookers', 'metric_time__day']
+ -- Aggregate Measures
+ SELECT
+ subq_13.ds AS metric_time__day
+ , COUNT(DISTINCT bookings_source_src_10001.guest_id) AS bookers
+ FROM ***************************.mf_time_spine subq_13
+ INNER JOIN
+ ***************************.fct_bookings bookings_source_src_10001
+ ON
+ (
+ DATE_TRUNC('day', bookings_source_src_10001.ds) <= subq_13.ds
+ ) AND (
+ DATE_TRUNC('day', bookings_source_src_10001.ds) > DATE_ADD('day', -2, subq_13.ds)
+ )
+ GROUP BY
+ subq_13.ds
+ ) subq_16
+ ON
+ subq_18.ds = subq_16.metric_time__day
+) subq_19
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
new file mode 100644
index 0000000000..f477645da3
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0.sql
@@ -0,0 +1,561 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_16.metric_time__day
+ , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) AS metric_time__day
+ , COALESCE(MAX(subq_7.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0
+ , MAX(subq_15.bookings_2_weeks_ago) AS bookings_2_weeks_ago
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_6.metric_time__day
+ , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_4.metric_time__day AS metric_time__day
+ , subq_3.bookings AS bookings
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_5.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_5
+ ) subq_4
+ LEFT OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ ) subq_3
+ ON
+ subq_4.metric_time__day = subq_3.metric_time__day
+ ) subq_6
+ ) subq_7
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_14.metric_time__day
+ , subq_14.bookings AS bookings_2_weeks_ago
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_13.metric_time__day
+ , SUM(subq_13.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_12.metric_time__day
+ , subq_12.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_10.metric_time__day AS metric_time__day
+ , subq_9.ds__day AS ds__day
+ , subq_9.ds__week AS ds__week
+ , subq_9.ds__month AS ds__month
+ , subq_9.ds__quarter AS ds__quarter
+ , subq_9.ds__year AS ds__year
+ , subq_9.ds__extract_year AS ds__extract_year
+ , subq_9.ds__extract_quarter AS ds__extract_quarter
+ , subq_9.ds__extract_month AS ds__extract_month
+ , subq_9.ds__extract_day AS ds__extract_day
+ , subq_9.ds__extract_dow AS ds__extract_dow
+ , subq_9.ds__extract_doy AS ds__extract_doy
+ , subq_9.ds_partitioned__day AS ds_partitioned__day
+ , subq_9.ds_partitioned__week AS ds_partitioned__week
+ , subq_9.ds_partitioned__month AS ds_partitioned__month
+ , subq_9.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_9.ds_partitioned__year AS ds_partitioned__year
+ , subq_9.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_9.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_9.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_9.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_9.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_9.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_9.paid_at__day AS paid_at__day
+ , subq_9.paid_at__week AS paid_at__week
+ , subq_9.paid_at__month AS paid_at__month
+ , subq_9.paid_at__quarter AS paid_at__quarter
+ , subq_9.paid_at__year AS paid_at__year
+ , subq_9.paid_at__extract_year AS paid_at__extract_year
+ , subq_9.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_9.paid_at__extract_month AS paid_at__extract_month
+ , subq_9.paid_at__extract_day AS paid_at__extract_day
+ , subq_9.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_9.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_9.booking__ds__day AS booking__ds__day
+ , subq_9.booking__ds__week AS booking__ds__week
+ , subq_9.booking__ds__month AS booking__ds__month
+ , subq_9.booking__ds__quarter AS booking__ds__quarter
+ , subq_9.booking__ds__year AS booking__ds__year
+ , subq_9.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_9.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_9.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_9.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_9.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_9.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_9.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_9.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_9.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_9.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_9.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_9.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_9.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_9.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_9.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_9.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_9.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_9.booking__paid_at__day AS booking__paid_at__day
+ , subq_9.booking__paid_at__week AS booking__paid_at__week
+ , subq_9.booking__paid_at__month AS booking__paid_at__month
+ , subq_9.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_9.booking__paid_at__year AS booking__paid_at__year
+ , subq_9.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_9.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_9.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_9.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_9.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_9.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_9.listing AS listing
+ , subq_9.guest AS guest
+ , subq_9.host AS host
+ , subq_9.booking__listing AS booking__listing
+ , subq_9.booking__guest AS booking__guest
+ , subq_9.booking__host AS booking__host
+ , subq_9.is_instant AS is_instant
+ , subq_9.booking__is_instant AS booking__is_instant
+ , subq_9.bookings AS bookings
+ , subq_9.instant_bookings AS instant_bookings
+ , subq_9.booking_value AS booking_value
+ , subq_9.max_booking_value AS max_booking_value
+ , subq_9.min_booking_value AS min_booking_value
+ , subq_9.bookers AS bookers
+ , subq_9.average_booking_value AS average_booking_value
+ , subq_9.referred_bookings AS referred_bookings
+ , subq_9.median_booking_value AS median_booking_value
+ , subq_9.booking_value_p99 AS booking_value_p99
+ , subq_9.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_9.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_9.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_11.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_11
+ ) subq_10
+ INNER JOIN (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_8.ds__day
+ , subq_8.ds__week
+ , subq_8.ds__month
+ , subq_8.ds__quarter
+ , subq_8.ds__year
+ , subq_8.ds__extract_year
+ , subq_8.ds__extract_quarter
+ , subq_8.ds__extract_month
+ , subq_8.ds__extract_day
+ , subq_8.ds__extract_dow
+ , subq_8.ds__extract_doy
+ , subq_8.ds_partitioned__day
+ , subq_8.ds_partitioned__week
+ , subq_8.ds_partitioned__month
+ , subq_8.ds_partitioned__quarter
+ , subq_8.ds_partitioned__year
+ , subq_8.ds_partitioned__extract_year
+ , subq_8.ds_partitioned__extract_quarter
+ , subq_8.ds_partitioned__extract_month
+ , subq_8.ds_partitioned__extract_day
+ , subq_8.ds_partitioned__extract_dow
+ , subq_8.ds_partitioned__extract_doy
+ , subq_8.paid_at__day
+ , subq_8.paid_at__week
+ , subq_8.paid_at__month
+ , subq_8.paid_at__quarter
+ , subq_8.paid_at__year
+ , subq_8.paid_at__extract_year
+ , subq_8.paid_at__extract_quarter
+ , subq_8.paid_at__extract_month
+ , subq_8.paid_at__extract_day
+ , subq_8.paid_at__extract_dow
+ , subq_8.paid_at__extract_doy
+ , subq_8.booking__ds__day
+ , subq_8.booking__ds__week
+ , subq_8.booking__ds__month
+ , subq_8.booking__ds__quarter
+ , subq_8.booking__ds__year
+ , subq_8.booking__ds__extract_year
+ , subq_8.booking__ds__extract_quarter
+ , subq_8.booking__ds__extract_month
+ , subq_8.booking__ds__extract_day
+ , subq_8.booking__ds__extract_dow
+ , subq_8.booking__ds__extract_doy
+ , subq_8.booking__ds_partitioned__day
+ , subq_8.booking__ds_partitioned__week
+ , subq_8.booking__ds_partitioned__month
+ , subq_8.booking__ds_partitioned__quarter
+ , subq_8.booking__ds_partitioned__year
+ , subq_8.booking__ds_partitioned__extract_year
+ , subq_8.booking__ds_partitioned__extract_quarter
+ , subq_8.booking__ds_partitioned__extract_month
+ , subq_8.booking__ds_partitioned__extract_day
+ , subq_8.booking__ds_partitioned__extract_dow
+ , subq_8.booking__ds_partitioned__extract_doy
+ , subq_8.booking__paid_at__day
+ , subq_8.booking__paid_at__week
+ , subq_8.booking__paid_at__month
+ , subq_8.booking__paid_at__quarter
+ , subq_8.booking__paid_at__year
+ , subq_8.booking__paid_at__extract_year
+ , subq_8.booking__paid_at__extract_quarter
+ , subq_8.booking__paid_at__extract_month
+ , subq_8.booking__paid_at__extract_day
+ , subq_8.booking__paid_at__extract_dow
+ , subq_8.booking__paid_at__extract_doy
+ , subq_8.ds__day AS metric_time__day
+ , subq_8.ds__week AS metric_time__week
+ , subq_8.ds__month AS metric_time__month
+ , subq_8.ds__quarter AS metric_time__quarter
+ , subq_8.ds__year AS metric_time__year
+ , subq_8.ds__extract_year AS metric_time__extract_year
+ , subq_8.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_8.ds__extract_month AS metric_time__extract_month
+ , subq_8.ds__extract_day AS metric_time__extract_day
+ , subq_8.ds__extract_dow AS metric_time__extract_dow
+ , subq_8.ds__extract_doy AS metric_time__extract_doy
+ , subq_8.listing
+ , subq_8.guest
+ , subq_8.host
+ , subq_8.booking__listing
+ , subq_8.booking__guest
+ , subq_8.booking__host
+ , subq_8.is_instant
+ , subq_8.booking__is_instant
+ , subq_8.bookings
+ , subq_8.instant_bookings
+ , subq_8.booking_value
+ , subq_8.max_booking_value
+ , subq_8.min_booking_value
+ , subq_8.bookers
+ , subq_8.average_booking_value
+ , subq_8.referred_bookings
+ , subq_8.median_booking_value
+ , subq_8.booking_value_p99
+ , subq_8.discrete_booking_value_p99
+ , subq_8.approximate_continuous_booking_value_p99
+ , subq_8.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_8
+ ) subq_9
+ ON
+ DATE_ADD('day', -14, subq_10.metric_time__day) = subq_9.metric_time__day
+ ) subq_12
+ ) subq_13
+ GROUP BY
+ subq_13.metric_time__day
+ ) subq_14
+ ) subq_15
+ ON
+ subq_7.metric_time__day = subq_15.metric_time__day
+ GROUP BY
+ COALESCE(subq_7.metric_time__day, subq_15.metric_time__day)
+) subq_16
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql
new file mode 100644
index 0000000000..070f4444b9
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_derived_fill_nulls_for_one_input_metric__plan0_optimized.sql
@@ -0,0 +1,71 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , bookings_fill_nulls_with_0 - bookings_2_weeks_ago AS bookings_growth_2_weeks_fill_nulls_with_0_for_non_offset
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) AS metric_time__day
+ , COALESCE(MAX(subq_24.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0
+ , MAX(subq_32.bookings_2_weeks_ago) AS bookings_2_weeks_ago
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_22.ds AS metric_time__day
+ , subq_20.bookings AS bookings
+ FROM ***************************.mf_time_spine subq_22
+ LEFT OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_19
+ GROUP BY
+ metric_time__day
+ ) subq_20
+ ON
+ subq_22.ds = subq_20.metric_time__day
+ ) subq_23
+ ) subq_24
+ FULL OUTER JOIN (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_28.ds AS metric_time__day
+ , SUM(subq_26.bookings) AS bookings_2_weeks_ago
+ FROM ***************************.mf_time_spine subq_28
+ 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_10001
+ ) subq_26
+ ON
+ DATE_ADD('day', -14, subq_28.ds) = subq_26.metric_time__day
+ GROUP BY
+ subq_28.ds
+ ) subq_32
+ ON
+ subq_24.metric_time__day = subq_32.metric_time__day
+ GROUP BY
+ COALESCE(subq_24.metric_time__day, subq_32.metric_time__day)
+) subq_33
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql
new file mode 100644
index 0000000000..8de2818d2b
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0.sql
@@ -0,0 +1,228 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_6.metric_time__day
+ , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_4.metric_time__day AS metric_time__day
+ , subq_3.bookings AS bookings
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_5.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_5
+ ) subq_4
+ LEFT OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ ) subq_3
+ ON
+ subq_4.metric_time__day = subq_3.metric_time__day
+) subq_6
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql
new file mode 100644
index 0000000000..adeb9c3151
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_metric_time__plan0_optimized.sql
@@ -0,0 +1,31 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_12.ds AS metric_time__day
+ , subq_10.bookings AS bookings
+ FROM ***************************.mf_time_spine subq_12
+ LEFT OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_9
+ GROUP BY
+ metric_time__day
+ ) subq_10
+ ON
+ subq_12.ds = subq_10.metric_time__day
+) subq_13
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql
new file mode 100644
index 0000000000..b1d689ff06
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0.sql
@@ -0,0 +1,230 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_6.metric_time__month
+ , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_4.metric_time__month AS metric_time__month
+ , subq_3.bookings AS bookings
+ FROM (
+ -- Date Spine
+ SELECT
+ DATE_TRUNC('month', subq_5.ds) AS metric_time__month
+ FROM ***************************.mf_time_spine subq_5
+ GROUP BY
+ DATE_TRUNC('month', subq_5.ds)
+ ) subq_4
+ LEFT OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__month
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__month']
+ SELECT
+ subq_1.metric_time__month
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__month
+ ) subq_3
+ ON
+ subq_4.metric_time__month = subq_3.metric_time__month
+) subq_6
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql
new file mode 100644
index 0000000000..9b48edbdd6
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_month__plan0_optimized.sql
@@ -0,0 +1,38 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__month
+ , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_11.metric_time__month AS metric_time__month
+ , subq_10.bookings AS bookings
+ FROM (
+ -- Date Spine
+ SELECT
+ DATE_TRUNC('month', ds) AS metric_time__month
+ FROM ***************************.mf_time_spine subq_12
+ GROUP BY
+ DATE_TRUNC('month', ds)
+ ) subq_11
+ LEFT OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ metric_time__month
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__month']
+ SELECT
+ DATE_TRUNC('month', ds) AS metric_time__month
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_9
+ GROUP BY
+ metric_time__month
+ ) subq_10
+ ON
+ subq_11.metric_time__month = subq_10.metric_time__month
+) subq_13
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0.sql
new file mode 100644
index 0000000000..eefd911947
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0.sql
@@ -0,0 +1,214 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_3.booking__is_instant
+ , COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.booking__is_instant
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__is_instant']
+ SELECT
+ subq_1.booking__is_instant
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.booking__is_instant
+) subq_3
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0_optimized.sql
new file mode 100644
index 0000000000..f2e8924fa6
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0_optimized.sql
@@ -0,0 +1,22 @@
+-- Compute Metrics via Expressions
+SELECT
+ booking__is_instant
+ , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0
+FROM (
+ -- Aggregate Measures
+ SELECT
+ booking__is_instant
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__is_instant']
+ SELECT
+ is_instant AS booking__is_instant
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_6
+ GROUP BY
+ booking__is_instant
+) subq_7
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0.sql
new file mode 100644
index 0000000000..ab39f91c86
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0.sql
@@ -0,0 +1,214 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_3.booking__paid_at__day
+ , COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.booking__paid_at__day
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__paid_at__day']
+ SELECT
+ subq_1.booking__paid_at__day
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.booking__paid_at__day
+) subq_3
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0_optimized.sql
new file mode 100644
index 0000000000..52e3a373c3
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_with_0_with_non_metric_time__plan0_optimized.sql
@@ -0,0 +1,22 @@
+-- Compute Metrics via Expressions
+SELECT
+ booking__paid_at__day
+ , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0
+FROM (
+ -- Aggregate Measures
+ SELECT
+ booking__paid_at__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__paid_at__day']
+ SELECT
+ DATE_TRUNC('day', paid_at) AS booking__paid_at__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_6
+ GROUP BY
+ booking__paid_at__day
+) subq_7
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0.sql
new file mode 100644
index 0000000000..e08feb9c72
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0.sql
@@ -0,0 +1,214 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_3.metric_time__day
+ , COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0_without_time_spine
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+) subq_3
diff --git a/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0_optimized.sql b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0_optimized.sql
new file mode 100644
index 0000000000..a96360ac38
--- /dev/null
+++ b/metricflow/test/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/Trino/test_simple_fill_nulls_without_time_spine__plan0_optimized.sql
@@ -0,0 +1,22 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , COALESCE(bookings, 0) AS bookings_fill_nulls_with_0_without_time_spine
+FROM (
+ -- Aggregate Measures
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_6
+ GROUP BY
+ metric_time__day
+) subq_7
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
new file mode 100644
index 0000000000..9d17d27426
--- /dev/null
+++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0.sql
@@ -0,0 +1,547 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_13.metric_time__extract_dow
+ , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_4.metric_time__extract_dow, subq_12.metric_time__extract_dow) AS metric_time__extract_dow
+ , MAX(subq_4.bookings) AS bookings
+ , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__extract_dow
+ , subq_3.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__extract_dow
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__extract_dow']
+ SELECT
+ subq_1.metric_time__extract_dow
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__extract_dow
+ ) subq_3
+ ) subq_4
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_11.metric_time__extract_dow
+ , subq_11.bookings AS bookings_2_weeks_ago
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_10.metric_time__extract_dow
+ , SUM(subq_10.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__extract_dow']
+ SELECT
+ subq_9.metric_time__extract_dow
+ , subq_9.bookings
+ FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ EXTRACT(DAY_OF_WEEK FROM subq_7.metric_time__day) AS metric_time__extract_dow
+ , subq_6.ds__day AS ds__day
+ , subq_6.ds__week AS ds__week
+ , subq_6.ds__month AS ds__month
+ , subq_6.ds__quarter AS ds__quarter
+ , subq_6.ds__year AS ds__year
+ , subq_6.ds__extract_year AS ds__extract_year
+ , subq_6.ds__extract_quarter AS ds__extract_quarter
+ , subq_6.ds__extract_month AS ds__extract_month
+ , subq_6.ds__extract_day AS ds__extract_day
+ , subq_6.ds__extract_dow AS ds__extract_dow
+ , subq_6.ds__extract_doy AS ds__extract_doy
+ , subq_6.ds_partitioned__day AS ds_partitioned__day
+ , subq_6.ds_partitioned__week AS ds_partitioned__week
+ , subq_6.ds_partitioned__month AS ds_partitioned__month
+ , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_6.ds_partitioned__year AS ds_partitioned__year
+ , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_6.paid_at__day AS paid_at__day
+ , subq_6.paid_at__week AS paid_at__week
+ , subq_6.paid_at__month AS paid_at__month
+ , subq_6.paid_at__quarter AS paid_at__quarter
+ , subq_6.paid_at__year AS paid_at__year
+ , subq_6.paid_at__extract_year AS paid_at__extract_year
+ , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter
+ , subq_6.paid_at__extract_month AS paid_at__extract_month
+ , subq_6.paid_at__extract_day AS paid_at__extract_day
+ , subq_6.paid_at__extract_dow AS paid_at__extract_dow
+ , subq_6.paid_at__extract_doy AS paid_at__extract_doy
+ , subq_6.booking__ds__day AS booking__ds__day
+ , subq_6.booking__ds__week AS booking__ds__week
+ , subq_6.booking__ds__month AS booking__ds__month
+ , subq_6.booking__ds__quarter AS booking__ds__quarter
+ , subq_6.booking__ds__year AS booking__ds__year
+ , subq_6.booking__ds__extract_year AS booking__ds__extract_year
+ , subq_6.booking__ds__extract_quarter AS booking__ds__extract_quarter
+ , subq_6.booking__ds__extract_month AS booking__ds__extract_month
+ , subq_6.booking__ds__extract_day AS booking__ds__extract_day
+ , subq_6.booking__ds__extract_dow AS booking__ds__extract_dow
+ , subq_6.booking__ds__extract_doy AS booking__ds__extract_doy
+ , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day
+ , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week
+ , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month
+ , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter
+ , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year
+ , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year
+ , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter
+ , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month
+ , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day
+ , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow
+ , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy
+ , subq_6.booking__paid_at__day AS booking__paid_at__day
+ , subq_6.booking__paid_at__week AS booking__paid_at__week
+ , subq_6.booking__paid_at__month AS booking__paid_at__month
+ , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter
+ , subq_6.booking__paid_at__year AS booking__paid_at__year
+ , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year
+ , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter
+ , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month
+ , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day
+ , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow
+ , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy
+ , subq_6.listing AS listing
+ , subq_6.guest AS guest
+ , subq_6.host AS host
+ , subq_6.booking__listing AS booking__listing
+ , subq_6.booking__guest AS booking__guest
+ , subq_6.booking__host AS booking__host
+ , subq_6.is_instant AS is_instant
+ , subq_6.booking__is_instant AS booking__is_instant
+ , subq_6.bookings AS bookings
+ , subq_6.instant_bookings AS instant_bookings
+ , subq_6.booking_value AS booking_value
+ , subq_6.max_booking_value AS max_booking_value
+ , subq_6.min_booking_value AS min_booking_value
+ , subq_6.bookers AS bookers
+ , subq_6.average_booking_value AS average_booking_value
+ , subq_6.referred_bookings AS referred_bookings
+ , subq_6.median_booking_value AS median_booking_value
+ , subq_6.booking_value_p99 AS booking_value_p99
+ , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99
+ , subq_6.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99
+ , subq_6.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_8.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_8
+ ) subq_7
+ INNER JOIN (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.ds_partitioned__day
+ , subq_5.ds_partitioned__week
+ , subq_5.ds_partitioned__month
+ , subq_5.ds_partitioned__quarter
+ , subq_5.ds_partitioned__year
+ , subq_5.ds_partitioned__extract_year
+ , subq_5.ds_partitioned__extract_quarter
+ , subq_5.ds_partitioned__extract_month
+ , subq_5.ds_partitioned__extract_day
+ , subq_5.ds_partitioned__extract_dow
+ , subq_5.ds_partitioned__extract_doy
+ , subq_5.paid_at__day
+ , subq_5.paid_at__week
+ , subq_5.paid_at__month
+ , subq_5.paid_at__quarter
+ , subq_5.paid_at__year
+ , subq_5.paid_at__extract_year
+ , subq_5.paid_at__extract_quarter
+ , subq_5.paid_at__extract_month
+ , subq_5.paid_at__extract_day
+ , subq_5.paid_at__extract_dow
+ , subq_5.paid_at__extract_doy
+ , subq_5.booking__ds__day
+ , subq_5.booking__ds__week
+ , subq_5.booking__ds__month
+ , subq_5.booking__ds__quarter
+ , subq_5.booking__ds__year
+ , subq_5.booking__ds__extract_year
+ , subq_5.booking__ds__extract_quarter
+ , subq_5.booking__ds__extract_month
+ , subq_5.booking__ds__extract_day
+ , subq_5.booking__ds__extract_dow
+ , subq_5.booking__ds__extract_doy
+ , subq_5.booking__ds_partitioned__day
+ , subq_5.booking__ds_partitioned__week
+ , subq_5.booking__ds_partitioned__month
+ , subq_5.booking__ds_partitioned__quarter
+ , subq_5.booking__ds_partitioned__year
+ , subq_5.booking__ds_partitioned__extract_year
+ , subq_5.booking__ds_partitioned__extract_quarter
+ , subq_5.booking__ds_partitioned__extract_month
+ , subq_5.booking__ds_partitioned__extract_day
+ , subq_5.booking__ds_partitioned__extract_dow
+ , subq_5.booking__ds_partitioned__extract_doy
+ , subq_5.booking__paid_at__day
+ , subq_5.booking__paid_at__week
+ , subq_5.booking__paid_at__month
+ , subq_5.booking__paid_at__quarter
+ , subq_5.booking__paid_at__year
+ , subq_5.booking__paid_at__extract_year
+ , subq_5.booking__paid_at__extract_quarter
+ , subq_5.booking__paid_at__extract_month
+ , subq_5.booking__paid_at__extract_day
+ , subq_5.booking__paid_at__extract_dow
+ , subq_5.booking__paid_at__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.listing
+ , subq_5.guest
+ , subq_5.host
+ , subq_5.booking__listing
+ , subq_5.booking__guest
+ , subq_5.booking__host
+ , subq_5.is_instant
+ , subq_5.booking__is_instant
+ , subq_5.bookings
+ , subq_5.instant_bookings
+ , subq_5.booking_value
+ , subq_5.max_booking_value
+ , subq_5.min_booking_value
+ , subq_5.bookers
+ , subq_5.average_booking_value
+ , subq_5.referred_bookings
+ , subq_5.median_booking_value
+ , subq_5.booking_value_p99
+ , subq_5.discrete_booking_value_p99
+ , subq_5.approximate_continuous_booking_value_p99
+ , subq_5.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_5
+ ) subq_6
+ ON
+ DATE_ADD('day', -14, subq_7.metric_time__day) = subq_6.metric_time__day
+ ) subq_9
+ ) subq_10
+ GROUP BY
+ subq_10.metric_time__extract_dow
+ ) subq_11
+ ) subq_12
+ ON
+ subq_4.metric_time__extract_dow = subq_12.metric_time__extract_dow
+ GROUP BY
+ COALESCE(subq_4.metric_time__extract_dow, subq_12.metric_time__extract_dow)
+) subq_13
diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql
new file mode 100644
index 0000000000..01ce251cdf
--- /dev/null
+++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_offset_window_with_date_part__plan0_optimized.sql
@@ -0,0 +1,57 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__extract_dow
+ , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_18.metric_time__extract_dow, subq_26.metric_time__extract_dow) AS metric_time__extract_dow
+ , MAX(subq_18.bookings) AS bookings
+ , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago
+ FROM (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__extract_dow
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__extract_dow']
+ SELECT
+ EXTRACT(DAY_OF_WEEK FROM ds) AS metric_time__extract_dow
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_16
+ GROUP BY
+ metric_time__extract_dow
+ ) subq_18
+ FULL OUTER JOIN (
+ -- Join to Time Spine Dataset
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__extract_dow']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ EXTRACT(DAY_OF_WEEK FROM subq_22.ds) AS metric_time__extract_dow
+ , SUM(subq_20.bookings) AS bookings_2_weeks_ago
+ FROM ***************************.mf_time_spine subq_22
+ 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_10001
+ ) subq_20
+ ON
+ DATE_ADD('day', -14, subq_22.ds) = subq_20.metric_time__day
+ GROUP BY
+ EXTRACT(DAY_OF_WEEK FROM subq_22.ds)
+ ) subq_26
+ ON
+ subq_18.metric_time__extract_dow = subq_26.metric_time__extract_dow
+ GROUP BY
+ COALESCE(subq_18.metric_time__extract_dow, subq_26.metric_time__extract_dow)
+) subq_27
diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0.sql
new file mode 100644
index 0000000000..34e8a1db84
--- /dev/null
+++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0.sql
@@ -0,0 +1,214 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_3.metric_time__extract_dow
+ , subq_3.bookings
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__extract_dow
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__extract_dow']
+ SELECT
+ subq_1.metric_time__extract_dow
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__extract_dow
+) subq_3
diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0_optimized.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0_optimized.sql
new file mode 100644
index 0000000000..2466bb697d
--- /dev/null
+++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_date_part__plan0_optimized.sql
@@ -0,0 +1,17 @@
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__extract_dow
+ , SUM(bookings) AS bookings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__extract_dow']
+ SELECT
+ EXTRACT(DAY_OF_WEEK FROM ds) AS metric_time__extract_dow
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_6
+GROUP BY
+ metric_time__extract_dow
diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0.sql
new file mode 100644
index 0000000000..2ed67b0ebb
--- /dev/null
+++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0.sql
@@ -0,0 +1,240 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_3.metric_time__extract_year
+ , subq_3.metric_time__extract_quarter
+ , subq_3.metric_time__extract_month
+ , subq_3.metric_time__extract_day
+ , subq_3.metric_time__extract_dow
+ , subq_3.metric_time__extract_doy
+ , subq_3.bookings
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__extract_year
+ , subq_2.metric_time__extract_quarter
+ , subq_2.metric_time__extract_month
+ , subq_2.metric_time__extract_day
+ , subq_2.metric_time__extract_dow
+ , subq_2.metric_time__extract_doy
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings',
+ -- 'metric_time__extract_day',
+ -- 'metric_time__extract_dow',
+ -- 'metric_time__extract_doy',
+ -- 'metric_time__extract_month',
+ -- 'metric_time__extract_quarter',
+ -- 'metric_time__extract_year']
+ SELECT
+ subq_1.metric_time__extract_year
+ , subq_1.metric_time__extract_quarter
+ , subq_1.metric_time__extract_month
+ , subq_1.metric_time__extract_day
+ , subq_1.metric_time__extract_dow
+ , subq_1.metric_time__extract_doy
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__extract_year
+ , subq_2.metric_time__extract_quarter
+ , subq_2.metric_time__extract_month
+ , subq_2.metric_time__extract_day
+ , subq_2.metric_time__extract_dow
+ , subq_2.metric_time__extract_doy
+) subq_3
diff --git a/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0_optimized.sql b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0_optimized.sql
new file mode 100644
index 0000000000..8e17b03eb3
--- /dev/null
+++ b/metricflow/test/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/Trino/test_simple_query_with_multiple_date_parts__plan0_optimized.sql
@@ -0,0 +1,38 @@
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__extract_year
+ , metric_time__extract_quarter
+ , metric_time__extract_month
+ , metric_time__extract_day
+ , metric_time__extract_dow
+ , metric_time__extract_doy
+ , SUM(bookings) AS bookings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings',
+ -- 'metric_time__extract_day',
+ -- 'metric_time__extract_dow',
+ -- 'metric_time__extract_doy',
+ -- 'metric_time__extract_month',
+ -- 'metric_time__extract_quarter',
+ -- 'metric_time__extract_year']
+ SELECT
+ EXTRACT(year FROM ds) AS metric_time__extract_year
+ , EXTRACT(quarter FROM ds) AS metric_time__extract_quarter
+ , EXTRACT(month FROM ds) AS metric_time__extract_month
+ , EXTRACT(day FROM ds) AS metric_time__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS metric_time__extract_dow
+ , EXTRACT(doy FROM ds) AS metric_time__extract_doy
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_6
+GROUP BY
+ metric_time__extract_year
+ , metric_time__extract_quarter
+ , metric_time__extract_month
+ , metric_time__extract_day
+ , metric_time__extract_dow
+ , metric_time__extract_doy
diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0.sql
new file mode 100644
index 0000000000..28d7cd941d
--- /dev/null
+++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0.sql
@@ -0,0 +1,181 @@
+-- Metric Time Dimension 'paid_at'
+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.paid_at__day AS metric_time__day
+ , subq_0.paid_at__week AS metric_time__week
+ , subq_0.paid_at__month AS metric_time__month
+ , subq_0.paid_at__quarter AS metric_time__quarter
+ , subq_0.paid_at__year AS metric_time__year
+ , subq_0.paid_at__extract_year AS metric_time__extract_year
+ , subq_0.paid_at__extract_quarter AS metric_time__extract_quarter
+ , subq_0.paid_at__extract_month AS metric_time__extract_month
+ , subq_0.paid_at__extract_day AS metric_time__extract_day
+ , subq_0.paid_at__extract_dow AS metric_time__extract_dow
+ , subq_0.paid_at__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.booking_payments
+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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_0
diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0_optimized.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0_optimized.sql
new file mode 100644
index 0000000000..6a63f5fde6
--- /dev/null
+++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_non_primary_time__plan0_optimized.sql
@@ -0,0 +1,90 @@
+-- Read Elements From Semantic Model 'bookings_source'
+-- Metric Time Dimension 'paid_at'
+SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('week', ds) AS ds__week
+ , DATE_TRUNC('month', ds) AS ds__month
+ , DATE_TRUNC('quarter', ds) AS ds__quarter
+ , DATE_TRUNC('year', ds) AS ds__year
+ , EXTRACT(year FROM ds) AS ds__extract_year
+ , EXTRACT(quarter FROM ds) AS ds__extract_quarter
+ , EXTRACT(month FROM ds) AS ds__extract_month
+ , EXTRACT(day FROM ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow
+ , EXTRACT(doy FROM ds) AS ds__extract_doy
+ , DATE_TRUNC('day', ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', paid_at) AS paid_at__day
+ , DATE_TRUNC('week', paid_at) AS paid_at__week
+ , DATE_TRUNC('month', paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', paid_at) AS paid_at__year
+ , EXTRACT(year FROM paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM paid_at) AS paid_at__extract_doy
+ , DATE_TRUNC('day', ds) AS booking__ds__day
+ , DATE_TRUNC('week', ds) AS booking__ds__week
+ , DATE_TRUNC('month', ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', ds) AS booking__ds__year
+ , EXTRACT(year FROM ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM paid_at) AS booking__paid_at__extract_doy
+ , DATE_TRUNC('day', paid_at) AS metric_time__day
+ , DATE_TRUNC('week', paid_at) AS metric_time__week
+ , DATE_TRUNC('month', paid_at) AS metric_time__month
+ , DATE_TRUNC('quarter', paid_at) AS metric_time__quarter
+ , DATE_TRUNC('year', paid_at) AS metric_time__year
+ , EXTRACT(year FROM paid_at) AS metric_time__extract_year
+ , EXTRACT(quarter FROM paid_at) AS metric_time__extract_quarter
+ , EXTRACT(month FROM paid_at) AS metric_time__extract_month
+ , EXTRACT(day FROM paid_at) AS metric_time__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM paid_at) AS metric_time__extract_dow
+ , EXTRACT(doy FROM paid_at) AS metric_time__extract_doy
+ , listing_id AS listing
+ , guest_id AS guest
+ , host_id AS host
+ , listing_id AS booking__listing
+ , guest_id AS booking__guest
+ , host_id AS booking__host
+ , is_instant
+ , is_instant AS booking__is_instant
+ , booking_value AS booking_payments
+FROM ***************************.fct_bookings bookings_source_src_10001
diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0.sql
new file mode 100644
index 0000000000..1de66ca95f
--- /dev/null
+++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0.sql
@@ -0,0 +1,193 @@
+-- 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_0
diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0_optimized.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0_optimized.sql
new file mode 100644
index 0000000000..8d46cda654
--- /dev/null
+++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_metric_time_dimension_transform_node_using_primary_time__plan0_optimized.sql
@@ -0,0 +1,102 @@
+-- Read Elements From Semantic Model 'bookings_source'
+-- Metric Time Dimension 'ds'
+SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , DATE_TRUNC('week', ds) AS ds__week
+ , DATE_TRUNC('month', ds) AS ds__month
+ , DATE_TRUNC('quarter', ds) AS ds__quarter
+ , DATE_TRUNC('year', ds) AS ds__year
+ , EXTRACT(year FROM ds) AS ds__extract_year
+ , EXTRACT(quarter FROM ds) AS ds__extract_quarter
+ , EXTRACT(month FROM ds) AS ds__extract_month
+ , EXTRACT(day FROM ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS ds__extract_dow
+ , EXTRACT(doy FROM ds) AS ds__extract_doy
+ , DATE_TRUNC('day', ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', paid_at) AS paid_at__day
+ , DATE_TRUNC('week', paid_at) AS paid_at__week
+ , DATE_TRUNC('month', paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', paid_at) AS paid_at__year
+ , EXTRACT(year FROM paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM paid_at) AS paid_at__extract_doy
+ , DATE_TRUNC('day', ds) AS booking__ds__day
+ , DATE_TRUNC('week', ds) AS booking__ds__week
+ , DATE_TRUNC('month', ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', ds) AS booking__ds__year
+ , EXTRACT(year FROM ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM paid_at) AS booking__paid_at__extract_doy
+ , DATE_TRUNC('day', ds) AS metric_time__day
+ , DATE_TRUNC('week', ds) AS metric_time__week
+ , DATE_TRUNC('month', ds) AS metric_time__month
+ , DATE_TRUNC('quarter', ds) AS metric_time__quarter
+ , DATE_TRUNC('year', ds) AS metric_time__year
+ , EXTRACT(year FROM ds) AS metric_time__extract_year
+ , EXTRACT(quarter FROM ds) AS metric_time__extract_quarter
+ , EXTRACT(month FROM ds) AS metric_time__extract_month
+ , EXTRACT(day FROM ds) AS metric_time__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM ds) AS metric_time__extract_dow
+ , EXTRACT(doy FROM ds) AS metric_time__extract_doy
+ , listing_id AS listing
+ , guest_id AS guest
+ , host_id AS host
+ , listing_id AS booking__listing
+ , guest_id AS booking__guest
+ , host_id AS booking__host
+ , is_instant
+ , is_instant AS booking__is_instant
+ , 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , booking_value
+ , booking_value AS max_booking_value
+ , booking_value AS min_booking_value
+ , guest_id AS bookers
+ , booking_value AS average_booking_value
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , booking_value AS median_booking_value
+ , booking_value AS booking_value_p99
+ , booking_value AS discrete_booking_value_p99
+ , booking_value AS approximate_continuous_booking_value_p99
+ , booking_value AS approximate_discrete_booking_value_p99
+FROM ***************************.fct_bookings bookings_source_src_10001
diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql
new file mode 100644
index 0000000000..9c69a8dd8b
--- /dev/null
+++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0.sql
@@ -0,0 +1,429 @@
+-- Combine Aggregated Outputs
+SELECT
+ COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day
+ , MAX(subq_4.bookings) AS bookings
+ , MAX(subq_9.booking_payments) AS booking_payments
+FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ ) subq_3
+) subq_4
+FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_8.metric_time__day
+ , subq_8.booking_payments
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_7.metric_time__day
+ , SUM(subq_7.booking_payments) AS booking_payments
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_payments', 'metric_time__day']
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.booking_payments
+ FROM (
+ -- Metric Time Dimension 'paid_at'
+ SELECT
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.ds_partitioned__day
+ , subq_5.ds_partitioned__week
+ , subq_5.ds_partitioned__month
+ , subq_5.ds_partitioned__quarter
+ , subq_5.ds_partitioned__year
+ , subq_5.ds_partitioned__extract_year
+ , subq_5.ds_partitioned__extract_quarter
+ , subq_5.ds_partitioned__extract_month
+ , subq_5.ds_partitioned__extract_day
+ , subq_5.ds_partitioned__extract_dow
+ , subq_5.ds_partitioned__extract_doy
+ , subq_5.paid_at__day
+ , subq_5.paid_at__week
+ , subq_5.paid_at__month
+ , subq_5.paid_at__quarter
+ , subq_5.paid_at__year
+ , subq_5.paid_at__extract_year
+ , subq_5.paid_at__extract_quarter
+ , subq_5.paid_at__extract_month
+ , subq_5.paid_at__extract_day
+ , subq_5.paid_at__extract_dow
+ , subq_5.paid_at__extract_doy
+ , subq_5.booking__ds__day
+ , subq_5.booking__ds__week
+ , subq_5.booking__ds__month
+ , subq_5.booking__ds__quarter
+ , subq_5.booking__ds__year
+ , subq_5.booking__ds__extract_year
+ , subq_5.booking__ds__extract_quarter
+ , subq_5.booking__ds__extract_month
+ , subq_5.booking__ds__extract_day
+ , subq_5.booking__ds__extract_dow
+ , subq_5.booking__ds__extract_doy
+ , subq_5.booking__ds_partitioned__day
+ , subq_5.booking__ds_partitioned__week
+ , subq_5.booking__ds_partitioned__month
+ , subq_5.booking__ds_partitioned__quarter
+ , subq_5.booking__ds_partitioned__year
+ , subq_5.booking__ds_partitioned__extract_year
+ , subq_5.booking__ds_partitioned__extract_quarter
+ , subq_5.booking__ds_partitioned__extract_month
+ , subq_5.booking__ds_partitioned__extract_day
+ , subq_5.booking__ds_partitioned__extract_dow
+ , subq_5.booking__ds_partitioned__extract_doy
+ , subq_5.booking__paid_at__day
+ , subq_5.booking__paid_at__week
+ , subq_5.booking__paid_at__month
+ , subq_5.booking__paid_at__quarter
+ , subq_5.booking__paid_at__year
+ , subq_5.booking__paid_at__extract_year
+ , subq_5.booking__paid_at__extract_quarter
+ , subq_5.booking__paid_at__extract_month
+ , subq_5.booking__paid_at__extract_day
+ , subq_5.booking__paid_at__extract_dow
+ , subq_5.booking__paid_at__extract_doy
+ , subq_5.paid_at__day AS metric_time__day
+ , subq_5.paid_at__week AS metric_time__week
+ , subq_5.paid_at__month AS metric_time__month
+ , subq_5.paid_at__quarter AS metric_time__quarter
+ , subq_5.paid_at__year AS metric_time__year
+ , subq_5.paid_at__extract_year AS metric_time__extract_year
+ , subq_5.paid_at__extract_quarter AS metric_time__extract_quarter
+ , subq_5.paid_at__extract_month AS metric_time__extract_month
+ , subq_5.paid_at__extract_day AS metric_time__extract_day
+ , subq_5.paid_at__extract_dow AS metric_time__extract_dow
+ , subq_5.paid_at__extract_doy AS metric_time__extract_doy
+ , subq_5.listing
+ , subq_5.guest
+ , subq_5.host
+ , subq_5.booking__listing
+ , subq_5.booking__guest
+ , subq_5.booking__host
+ , subq_5.is_instant
+ , subq_5.booking__is_instant
+ , subq_5.booking_payments
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_5
+ ) subq_6
+ ) subq_7
+ GROUP BY
+ subq_7.metric_time__day
+ ) subq_8
+) subq_9
+ON
+ subq_4.metric_time__day = subq_9.metric_time__day
+GROUP BY
+ COALESCE(subq_4.metric_time__day, subq_9.metric_time__day)
diff --git a/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql
new file mode 100644
index 0000000000..2f965192ba
--- /dev/null
+++ b/metricflow/test/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/Trino/test_simple_query_with_metric_time_dimension__plan0_optimized.sql
@@ -0,0 +1,42 @@
+-- Combine Aggregated Outputs
+SELECT
+ COALESCE(subq_14.metric_time__day, subq_19.metric_time__day) AS metric_time__day
+ , MAX(subq_14.bookings) AS bookings
+ , MAX(subq_19.booking_payments) AS booking_payments
+FROM (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_12
+ GROUP BY
+ metric_time__day
+) subq_14
+FULL OUTER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'paid_at'
+ -- Pass Only Elements:
+ -- ['booking_payments', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ DATE_TRUNC('day', paid_at) AS metric_time__day
+ , SUM(booking_value) AS booking_payments
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ GROUP BY
+ DATE_TRUNC('day', paid_at)
+) subq_19
+ON
+ subq_14.metric_time__day = subq_19.metric_time__day
+GROUP BY
+ COALESCE(subq_14.metric_time__day, subq_19.metric_time__day)
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql
new file mode 100644
index 0000000000..97f0946ad6
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0.sql
@@ -0,0 +1,441 @@
+-- Combine Aggregated Outputs
+SELECT
+ COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day
+ , MAX(subq_4.bookings) AS bookings
+ , MAX(subq_9.booking_value) AS booking_value
+FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ ) subq_3
+) subq_4
+FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_8.metric_time__day
+ , subq_8.booking_value
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_7.metric_time__day
+ , SUM(subq_7.booking_value) AS booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.booking_value
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.ds_partitioned__day
+ , subq_5.ds_partitioned__week
+ , subq_5.ds_partitioned__month
+ , subq_5.ds_partitioned__quarter
+ , subq_5.ds_partitioned__year
+ , subq_5.ds_partitioned__extract_year
+ , subq_5.ds_partitioned__extract_quarter
+ , subq_5.ds_partitioned__extract_month
+ , subq_5.ds_partitioned__extract_day
+ , subq_5.ds_partitioned__extract_dow
+ , subq_5.ds_partitioned__extract_doy
+ , subq_5.paid_at__day
+ , subq_5.paid_at__week
+ , subq_5.paid_at__month
+ , subq_5.paid_at__quarter
+ , subq_5.paid_at__year
+ , subq_5.paid_at__extract_year
+ , subq_5.paid_at__extract_quarter
+ , subq_5.paid_at__extract_month
+ , subq_5.paid_at__extract_day
+ , subq_5.paid_at__extract_dow
+ , subq_5.paid_at__extract_doy
+ , subq_5.booking__ds__day
+ , subq_5.booking__ds__week
+ , subq_5.booking__ds__month
+ , subq_5.booking__ds__quarter
+ , subq_5.booking__ds__year
+ , subq_5.booking__ds__extract_year
+ , subq_5.booking__ds__extract_quarter
+ , subq_5.booking__ds__extract_month
+ , subq_5.booking__ds__extract_day
+ , subq_5.booking__ds__extract_dow
+ , subq_5.booking__ds__extract_doy
+ , subq_5.booking__ds_partitioned__day
+ , subq_5.booking__ds_partitioned__week
+ , subq_5.booking__ds_partitioned__month
+ , subq_5.booking__ds_partitioned__quarter
+ , subq_5.booking__ds_partitioned__year
+ , subq_5.booking__ds_partitioned__extract_year
+ , subq_5.booking__ds_partitioned__extract_quarter
+ , subq_5.booking__ds_partitioned__extract_month
+ , subq_5.booking__ds_partitioned__extract_day
+ , subq_5.booking__ds_partitioned__extract_dow
+ , subq_5.booking__ds_partitioned__extract_doy
+ , subq_5.booking__paid_at__day
+ , subq_5.booking__paid_at__week
+ , subq_5.booking__paid_at__month
+ , subq_5.booking__paid_at__quarter
+ , subq_5.booking__paid_at__year
+ , subq_5.booking__paid_at__extract_year
+ , subq_5.booking__paid_at__extract_quarter
+ , subq_5.booking__paid_at__extract_month
+ , subq_5.booking__paid_at__extract_day
+ , subq_5.booking__paid_at__extract_dow
+ , subq_5.booking__paid_at__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.listing
+ , subq_5.guest
+ , subq_5.host
+ , subq_5.booking__listing
+ , subq_5.booking__guest
+ , subq_5.booking__host
+ , subq_5.is_instant
+ , subq_5.booking__is_instant
+ , subq_5.bookings
+ , subq_5.instant_bookings
+ , subq_5.booking_value
+ , subq_5.max_booking_value
+ , subq_5.min_booking_value
+ , subq_5.bookers
+ , subq_5.average_booking_value
+ , subq_5.referred_bookings
+ , subq_5.median_booking_value
+ , subq_5.booking_value_p99
+ , subq_5.discrete_booking_value_p99
+ , subq_5.approximate_continuous_booking_value_p99
+ , subq_5.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_5
+ ) subq_6
+ ) subq_7
+ GROUP BY
+ subq_7.metric_time__day
+ ) subq_8
+) subq_9
+ON
+ subq_4.metric_time__day = subq_9.metric_time__day
+GROUP BY
+ COALESCE(subq_4.metric_time__day, subq_9.metric_time__day)
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql
new file mode 100644
index 0000000000..d2cebbcf57
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_common_semantic_model__plan0_optimized.sql
@@ -0,0 +1,42 @@
+-- Combine Aggregated Outputs
+SELECT
+ COALESCE(subq_14.metric_time__day, subq_19.metric_time__day) AS metric_time__day
+ , MAX(subq_14.bookings) AS bookings
+ , MAX(subq_19.booking_value) AS booking_value
+FROM (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_12
+ GROUP BY
+ metric_time__day
+) subq_14
+FULL OUTER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , SUM(booking_value) AS booking_value
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ GROUP BY
+ DATE_TRUNC('day', ds)
+) subq_19
+ON
+ subq_14.metric_time__day = subq_19.metric_time__day
+GROUP BY
+ COALESCE(subq_14.metric_time__day, subq_19.metric_time__day)
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql
new file mode 100644
index 0000000000..62c4d422d7
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0.sql
@@ -0,0 +1,135 @@
+-- Order By ['listing__country_latest'] Limit 100
+SELECT
+ subq_2.listing__country_latest
+FROM (
+ -- Pass Only Elements:
+ -- ['listing__country_latest']
+ SELECT
+ subq_1.listing__country_latest
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.created_at__day
+ , subq_0.created_at__week
+ , subq_0.created_at__month
+ , subq_0.created_at__quarter
+ , subq_0.created_at__year
+ , subq_0.created_at__extract_year
+ , subq_0.created_at__extract_quarter
+ , subq_0.created_at__extract_month
+ , subq_0.created_at__extract_day
+ , subq_0.created_at__extract_dow
+ , subq_0.created_at__extract_doy
+ , subq_0.listing__ds__day
+ , subq_0.listing__ds__week
+ , subq_0.listing__ds__month
+ , subq_0.listing__ds__quarter
+ , subq_0.listing__ds__year
+ , subq_0.listing__ds__extract_year
+ , subq_0.listing__ds__extract_quarter
+ , subq_0.listing__ds__extract_month
+ , subq_0.listing__ds__extract_day
+ , subq_0.listing__ds__extract_dow
+ , subq_0.listing__ds__extract_doy
+ , subq_0.listing__created_at__day
+ , subq_0.listing__created_at__week
+ , subq_0.listing__created_at__month
+ , subq_0.listing__created_at__quarter
+ , subq_0.listing__created_at__year
+ , subq_0.listing__created_at__extract_year
+ , subq_0.listing__created_at__extract_quarter
+ , subq_0.listing__created_at__extract_month
+ , subq_0.listing__created_at__extract_day
+ , subq_0.listing__created_at__extract_dow
+ , subq_0.listing__created_at__extract_doy
+ , subq_0.listing
+ , subq_0.user
+ , subq_0.listing__user
+ , subq_0.country_latest
+ , subq_0.is_lux_latest
+ , subq_0.capacity_latest
+ , subq_0.listing__country_latest
+ , subq_0.listing__is_lux_latest
+ , subq_0.listing__capacity_latest
+ , subq_0.listings
+ , subq_0.largest_listing
+ , subq_0.smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_0
+ WHERE listing__country_latest = 'us'
+ ) subq_1
+ GROUP BY
+ subq_1.listing__country_latest
+) subq_2
+ORDER BY subq_2.listing__country_latest DESC
+LIMIT 100
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql
new file mode 100644
index 0000000000..53c7bf823f
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_distinct_values__plan0_optimized.sql
@@ -0,0 +1,17 @@
+-- Constrain Output with WHERE
+-- Pass Only Elements:
+-- ['listing__country_latest']
+-- Order By ['listing__country_latest'] Limit 100
+SELECT
+ listing__country_latest
+FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ country AS listing__country_latest
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+) subq_3
+WHERE listing__country_latest = 'us'
+GROUP BY
+ listing__country_latest
+ORDER BY listing__country_latest DESC
+LIMIT 100
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql
new file mode 100644
index 0000000000..4a00c4a466
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0.sql
@@ -0,0 +1,387 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_10.booking__is_instant
+ , subq_10.bookings
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_9.booking__is_instant
+ , SUM(subq_9.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__is_instant']
+ SELECT
+ subq_8.booking__is_instant
+ , subq_8.bookings
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_7.booking__is_instant
+ , subq_7.listing__country_latest
+ , subq_7.bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__is_instant', 'listing__country_latest']
+ SELECT
+ subq_6.booking__is_instant
+ , subq_6.listing__country_latest
+ , subq_6.bookings
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_2.listing AS listing
+ , subq_2.booking__is_instant AS booking__is_instant
+ , subq_5.country_latest AS listing__country_latest
+ , subq_2.bookings AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__is_instant', 'listing']
+ SELECT
+ subq_1.listing
+ , subq_1.booking__is_instant
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['country_latest', 'listing']
+ SELECT
+ subq_4.listing
+ , subq_4.country_latest
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_3.ds__day
+ , subq_3.ds__week
+ , subq_3.ds__month
+ , subq_3.ds__quarter
+ , subq_3.ds__year
+ , subq_3.ds__extract_year
+ , subq_3.ds__extract_quarter
+ , subq_3.ds__extract_month
+ , subq_3.ds__extract_day
+ , subq_3.ds__extract_dow
+ , subq_3.ds__extract_doy
+ , subq_3.created_at__day
+ , subq_3.created_at__week
+ , subq_3.created_at__month
+ , subq_3.created_at__quarter
+ , subq_3.created_at__year
+ , subq_3.created_at__extract_year
+ , subq_3.created_at__extract_quarter
+ , subq_3.created_at__extract_month
+ , subq_3.created_at__extract_day
+ , subq_3.created_at__extract_dow
+ , subq_3.created_at__extract_doy
+ , subq_3.listing__ds__day
+ , subq_3.listing__ds__week
+ , subq_3.listing__ds__month
+ , subq_3.listing__ds__quarter
+ , subq_3.listing__ds__year
+ , subq_3.listing__ds__extract_year
+ , subq_3.listing__ds__extract_quarter
+ , subq_3.listing__ds__extract_month
+ , subq_3.listing__ds__extract_day
+ , subq_3.listing__ds__extract_dow
+ , subq_3.listing__ds__extract_doy
+ , subq_3.listing__created_at__day
+ , subq_3.listing__created_at__week
+ , subq_3.listing__created_at__month
+ , subq_3.listing__created_at__quarter
+ , subq_3.listing__created_at__year
+ , subq_3.listing__created_at__extract_year
+ , subq_3.listing__created_at__extract_quarter
+ , subq_3.listing__created_at__extract_month
+ , subq_3.listing__created_at__extract_day
+ , subq_3.listing__created_at__extract_dow
+ , subq_3.listing__created_at__extract_doy
+ , subq_3.ds__day AS metric_time__day
+ , subq_3.ds__week AS metric_time__week
+ , subq_3.ds__month AS metric_time__month
+ , subq_3.ds__quarter AS metric_time__quarter
+ , subq_3.ds__year AS metric_time__year
+ , subq_3.ds__extract_year AS metric_time__extract_year
+ , subq_3.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_3.ds__extract_month AS metric_time__extract_month
+ , subq_3.ds__extract_day AS metric_time__extract_day
+ , subq_3.ds__extract_dow AS metric_time__extract_dow
+ , subq_3.ds__extract_doy AS metric_time__extract_doy
+ , subq_3.listing
+ , subq_3.user
+ , subq_3.listing__user
+ , subq_3.country_latest
+ , subq_3.is_lux_latest
+ , subq_3.capacity_latest
+ , subq_3.listing__country_latest
+ , subq_3.listing__is_lux_latest
+ , subq_3.listing__capacity_latest
+ , subq_3.listings
+ , subq_3.largest_listing
+ , subq_3.smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_3
+ ) subq_4
+ ) subq_5
+ ON
+ subq_2.listing = subq_5.listing
+ ) subq_6
+ ) subq_7
+ WHERE listing__country_latest = 'us'
+ ) subq_8
+ ) subq_9
+ GROUP BY
+ subq_9.booking__is_instant
+) subq_10
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql
new file mode 100644
index 0000000000..d00b32fb24
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql
@@ -0,0 +1,35 @@
+-- Constrain Output with WHERE
+-- Pass Only Elements:
+-- ['bookings', 'booking__is_instant']
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ booking__is_instant
+ , SUM(bookings) AS bookings
+FROM (
+ -- Join Standard Outputs
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__is_instant', 'listing__country_latest']
+ SELECT
+ subq_13.booking__is_instant AS booking__is_instant
+ , listings_latest_src_10005.country AS listing__country_latest
+ , subq_13.bookings AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__is_instant', 'listing']
+ SELECT
+ listing_id AS listing
+ , is_instant AS booking__is_instant
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_13
+ LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_10005
+ ON
+ subq_13.listing = listings_latest_src_10005.listing_id
+) subq_18
+WHERE listing__country_latest = 'us'
+GROUP BY
+ booking__is_instant
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql
new file mode 100644
index 0000000000..7a5e1b4b86
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0.sql
@@ -0,0 +1,317 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_9.metric_time__day
+ , subq_9.bookings AS family_bookings
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_8.metric_time__day
+ , SUM(subq_8.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_7.metric_time__day
+ , subq_7.bookings
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.listing__capacity
+ , subq_6.bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'listing__capacity', 'metric_time__day']
+ SELECT
+ subq_5.metric_time__day
+ , subq_5.listing__capacity
+ , subq_5.bookings
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , subq_4.window_start__day AS listing__window_start__day
+ , subq_4.window_end__day AS listing__window_end__day
+ , subq_2.listing AS listing
+ , subq_4.capacity AS listing__capacity
+ , subq_2.bookings AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day', 'listing']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.listing
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.user
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.booking__user
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ 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_10017.booking_value
+ , bookings_source_src_10017.guest_id AS bookers
+ , bookings_source_src_10017.booking_value AS average_booking_value
+ , bookings_source_src_10017.booking_value AS booking_payments
+ , bookings_source_src_10017.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10017.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10017.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10017.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10017.listing_id AS listing
+ , bookings_source_src_10017.guest_id AS guest
+ , bookings_source_src_10017.host_id AS host
+ , bookings_source_src_10017.guest_id AS user
+ , bookings_source_src_10017.listing_id AS booking__listing
+ , bookings_source_src_10017.guest_id AS booking__guest
+ , bookings_source_src_10017.host_id AS booking__host
+ , bookings_source_src_10017.guest_id AS booking__user
+ FROM ***************************.fct_bookings bookings_source_src_10017
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['capacity', 'window_start__day', 'window_end__day', 'listing']
+ SELECT
+ subq_3.window_start__day
+ , subq_3.window_end__day
+ , subq_3.listing
+ , subq_3.capacity
+ FROM (
+ -- Read Elements From Semantic Model 'listings'
+ SELECT
+ listings_src_10019.active_from AS window_start__day
+ , DATE_TRUNC('week', listings_src_10019.active_from) AS window_start__week
+ , DATE_TRUNC('month', listings_src_10019.active_from) AS window_start__month
+ , DATE_TRUNC('quarter', listings_src_10019.active_from) AS window_start__quarter
+ , DATE_TRUNC('year', listings_src_10019.active_from) AS window_start__year
+ , EXTRACT(year FROM listings_src_10019.active_from) AS window_start__extract_year
+ , EXTRACT(quarter FROM listings_src_10019.active_from) AS window_start__extract_quarter
+ , EXTRACT(month FROM listings_src_10019.active_from) AS window_start__extract_month
+ , EXTRACT(day FROM listings_src_10019.active_from) AS window_start__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_from) AS window_start__extract_dow
+ , EXTRACT(doy FROM listings_src_10019.active_from) AS window_start__extract_doy
+ , listings_src_10019.active_to AS window_end__day
+ , DATE_TRUNC('week', listings_src_10019.active_to) AS window_end__week
+ , DATE_TRUNC('month', listings_src_10019.active_to) AS window_end__month
+ , DATE_TRUNC('quarter', listings_src_10019.active_to) AS window_end__quarter
+ , DATE_TRUNC('year', listings_src_10019.active_to) AS window_end__year
+ , EXTRACT(year FROM listings_src_10019.active_to) AS window_end__extract_year
+ , EXTRACT(quarter FROM listings_src_10019.active_to) AS window_end__extract_quarter
+ , EXTRACT(month FROM listings_src_10019.active_to) AS window_end__extract_month
+ , EXTRACT(day FROM listings_src_10019.active_to) AS window_end__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_to) AS window_end__extract_dow
+ , EXTRACT(doy FROM listings_src_10019.active_to) AS window_end__extract_doy
+ , listings_src_10019.country
+ , listings_src_10019.is_lux
+ , listings_src_10019.capacity
+ , listings_src_10019.active_from AS listing__window_start__day
+ , DATE_TRUNC('week', listings_src_10019.active_from) AS listing__window_start__week
+ , DATE_TRUNC('month', listings_src_10019.active_from) AS listing__window_start__month
+ , DATE_TRUNC('quarter', listings_src_10019.active_from) AS listing__window_start__quarter
+ , DATE_TRUNC('year', listings_src_10019.active_from) AS listing__window_start__year
+ , EXTRACT(year FROM listings_src_10019.active_from) AS listing__window_start__extract_year
+ , EXTRACT(quarter FROM listings_src_10019.active_from) AS listing__window_start__extract_quarter
+ , EXTRACT(month FROM listings_src_10019.active_from) AS listing__window_start__extract_month
+ , EXTRACT(day FROM listings_src_10019.active_from) AS listing__window_start__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_from) AS listing__window_start__extract_dow
+ , EXTRACT(doy FROM listings_src_10019.active_from) AS listing__window_start__extract_doy
+ , listings_src_10019.active_to AS listing__window_end__day
+ , DATE_TRUNC('week', listings_src_10019.active_to) AS listing__window_end__week
+ , DATE_TRUNC('month', listings_src_10019.active_to) AS listing__window_end__month
+ , DATE_TRUNC('quarter', listings_src_10019.active_to) AS listing__window_end__quarter
+ , DATE_TRUNC('year', listings_src_10019.active_to) AS listing__window_end__year
+ , EXTRACT(year FROM listings_src_10019.active_to) AS listing__window_end__extract_year
+ , EXTRACT(quarter FROM listings_src_10019.active_to) AS listing__window_end__extract_quarter
+ , EXTRACT(month FROM listings_src_10019.active_to) AS listing__window_end__extract_month
+ , EXTRACT(day FROM listings_src_10019.active_to) AS listing__window_end__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_to) AS listing__window_end__extract_dow
+ , EXTRACT(doy FROM listings_src_10019.active_to) AS listing__window_end__extract_doy
+ , listings_src_10019.country AS listing__country
+ , listings_src_10019.is_lux AS listing__is_lux
+ , listings_src_10019.capacity AS listing__capacity
+ , listings_src_10019.listing_id AS listing
+ , listings_src_10019.user_id AS user
+ , listings_src_10019.user_id AS listing__user
+ FROM ***************************.dim_listings listings_src_10019
+ ) subq_3
+ ) subq_4
+ ON
+ (
+ subq_2.listing = subq_4.listing
+ ) AND (
+ (
+ subq_2.metric_time__day >= subq_4.window_start__day
+ ) AND (
+ (
+ subq_2.metric_time__day < subq_4.window_end__day
+ ) OR (
+ subq_4.window_end__day IS NULL
+ )
+ )
+ )
+ ) subq_5
+ ) subq_6
+ WHERE listing__capacity > 2
+ ) subq_7
+ ) subq_8
+ GROUP BY
+ subq_8.metric_time__day
+) subq_9
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql
new file mode 100644
index 0000000000..662445e5ef
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_join_to_scd_dimension__plan0_optimized.sql
@@ -0,0 +1,47 @@
+-- Constrain Output with WHERE
+-- Pass Only Elements:
+-- ['bookings', 'metric_time__day']
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , SUM(bookings) AS family_bookings
+FROM (
+ -- Join Standard Outputs
+ -- Pass Only Elements:
+ -- ['bookings', 'listing__capacity', 'metric_time__day']
+ SELECT
+ subq_12.metric_time__day AS metric_time__day
+ , listings_src_10019.capacity AS listing__capacity
+ , subq_12.bookings AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day', 'listing']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , listing_id AS listing
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10017
+ ) subq_12
+ LEFT OUTER JOIN
+ ***************************.dim_listings listings_src_10019
+ ON
+ (
+ subq_12.listing = listings_src_10019.listing_id
+ ) AND (
+ (
+ subq_12.metric_time__day >= listings_src_10019.active_from
+ ) AND (
+ (
+ subq_12.metric_time__day < listings_src_10019.active_to
+ ) OR (
+ listings_src_10019.active_to IS NULL
+ )
+ )
+ )
+) subq_16
+WHERE listing__capacity > 2
+GROUP BY
+ metric_time__day
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0.sql
new file mode 100644
index 0000000000..c1430d3764
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0.sql
@@ -0,0 +1,221 @@
+-- Order By [] Limit 1
+SELECT
+ subq_4.ds__day
+ , subq_4.bookings
+FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.ds__day
+ , subq_3.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.ds__day
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'ds__day']
+ SELECT
+ subq_1.ds__day
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.ds__day
+ ) subq_3
+) subq_4
+LIMIT 1
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0_optimized.sql
new file mode 100644
index 0000000000..e52871ff7c
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_limit_rows__plan0_optimized.sql
@@ -0,0 +1,19 @@
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+-- Order By [] Limit 1
+SELECT
+ ds__day
+ , SUM(bookings) AS bookings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'ds__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS ds__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_7
+GROUP BY
+ ds__day
+LIMIT 1
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql
new file mode 100644
index 0000000000..7115d3825a
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0.sql
@@ -0,0 +1,151 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_3.listing__country_latest
+ , subq_3.listings
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_2.listing__country_latest
+ , SUM(subq_2.listings) AS listings
+ FROM (
+ -- Pass Only Elements:
+ -- ['listings', 'listing__country_latest']
+ SELECT
+ subq_1.listing__country_latest
+ , subq_1.listings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.created_at__day
+ , subq_0.created_at__week
+ , subq_0.created_at__month
+ , subq_0.created_at__quarter
+ , subq_0.created_at__year
+ , subq_0.created_at__extract_year
+ , subq_0.created_at__extract_quarter
+ , subq_0.created_at__extract_month
+ , subq_0.created_at__extract_day
+ , subq_0.created_at__extract_dow
+ , subq_0.created_at__extract_doy
+ , subq_0.listing__ds__day
+ , subq_0.listing__ds__week
+ , subq_0.listing__ds__month
+ , subq_0.listing__ds__quarter
+ , subq_0.listing__ds__year
+ , subq_0.listing__ds__extract_year
+ , subq_0.listing__ds__extract_quarter
+ , subq_0.listing__ds__extract_month
+ , subq_0.listing__ds__extract_day
+ , subq_0.listing__ds__extract_dow
+ , subq_0.listing__ds__extract_doy
+ , subq_0.listing__created_at__day
+ , subq_0.listing__created_at__week
+ , subq_0.listing__created_at__month
+ , subq_0.listing__created_at__quarter
+ , subq_0.listing__created_at__year
+ , subq_0.listing__created_at__extract_year
+ , subq_0.listing__created_at__extract_quarter
+ , subq_0.listing__created_at__extract_month
+ , subq_0.listing__created_at__extract_day
+ , subq_0.listing__created_at__extract_dow
+ , subq_0.listing__created_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.user
+ , subq_0.listing__user
+ , subq_0.country_latest
+ , subq_0.is_lux_latest
+ , subq_0.capacity_latest
+ , subq_0.listing__country_latest
+ , subq_0.listing__is_lux_latest
+ , subq_0.listing__capacity_latest
+ , subq_0.listings
+ , subq_0.largest_listing
+ , subq_0.smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.listing__country_latest
+) subq_3
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql
new file mode 100644
index 0000000000..2c5690447e
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_local_dimension_using_local_entity__plan0_optimized.sql
@@ -0,0 +1,17 @@
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ listing__country_latest
+ , SUM(listings) AS listings
+FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['listings', 'listing__country_latest']
+ SELECT
+ country AS listing__country_latest
+ , 1 AS listings
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+) subq_6
+GROUP BY
+ listing__country_latest
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql
new file mode 100644
index 0000000000..169e346efc
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0.sql
@@ -0,0 +1,1012 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_29.metric_time__day
+ , average_booking_value * bookings / NULLIF(booking_value, 0) AS lux_booking_value_rate_expr
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_11.metric_time__day, subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day
+ , MAX(subq_11.average_booking_value) AS average_booking_value
+ , MAX(subq_23.bookings) AS bookings
+ , MAX(subq_28.booking_value) AS booking_value
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_10.metric_time__day
+ , subq_10.average_booking_value
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_9.metric_time__day
+ , AVG(subq_9.average_booking_value) AS average_booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['average_booking_value', 'metric_time__day']
+ SELECT
+ subq_8.metric_time__day
+ , subq_8.average_booking_value
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_7.metric_time__day
+ , subq_7.listing__is_lux_latest
+ , subq_7.average_booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['average_booking_value', 'listing__is_lux_latest', 'metric_time__day']
+ SELECT
+ subq_6.metric_time__day
+ , subq_6.listing__is_lux_latest
+ , subq_6.average_booking_value
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , subq_2.listing AS listing
+ , subq_5.is_lux_latest AS listing__is_lux_latest
+ , subq_2.average_booking_value AS average_booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['average_booking_value', 'metric_time__day', 'listing']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.listing
+ , subq_1.average_booking_value
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['is_lux_latest', 'listing']
+ SELECT
+ subq_4.listing
+ , subq_4.is_lux_latest
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_3.ds__day
+ , subq_3.ds__week
+ , subq_3.ds__month
+ , subq_3.ds__quarter
+ , subq_3.ds__year
+ , subq_3.ds__extract_year
+ , subq_3.ds__extract_quarter
+ , subq_3.ds__extract_month
+ , subq_3.ds__extract_day
+ , subq_3.ds__extract_dow
+ , subq_3.ds__extract_doy
+ , subq_3.created_at__day
+ , subq_3.created_at__week
+ , subq_3.created_at__month
+ , subq_3.created_at__quarter
+ , subq_3.created_at__year
+ , subq_3.created_at__extract_year
+ , subq_3.created_at__extract_quarter
+ , subq_3.created_at__extract_month
+ , subq_3.created_at__extract_day
+ , subq_3.created_at__extract_dow
+ , subq_3.created_at__extract_doy
+ , subq_3.listing__ds__day
+ , subq_3.listing__ds__week
+ , subq_3.listing__ds__month
+ , subq_3.listing__ds__quarter
+ , subq_3.listing__ds__year
+ , subq_3.listing__ds__extract_year
+ , subq_3.listing__ds__extract_quarter
+ , subq_3.listing__ds__extract_month
+ , subq_3.listing__ds__extract_day
+ , subq_3.listing__ds__extract_dow
+ , subq_3.listing__ds__extract_doy
+ , subq_3.listing__created_at__day
+ , subq_3.listing__created_at__week
+ , subq_3.listing__created_at__month
+ , subq_3.listing__created_at__quarter
+ , subq_3.listing__created_at__year
+ , subq_3.listing__created_at__extract_year
+ , subq_3.listing__created_at__extract_quarter
+ , subq_3.listing__created_at__extract_month
+ , subq_3.listing__created_at__extract_day
+ , subq_3.listing__created_at__extract_dow
+ , subq_3.listing__created_at__extract_doy
+ , subq_3.ds__day AS metric_time__day
+ , subq_3.ds__week AS metric_time__week
+ , subq_3.ds__month AS metric_time__month
+ , subq_3.ds__quarter AS metric_time__quarter
+ , subq_3.ds__year AS metric_time__year
+ , subq_3.ds__extract_year AS metric_time__extract_year
+ , subq_3.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_3.ds__extract_month AS metric_time__extract_month
+ , subq_3.ds__extract_day AS metric_time__extract_day
+ , subq_3.ds__extract_dow AS metric_time__extract_dow
+ , subq_3.ds__extract_doy AS metric_time__extract_doy
+ , subq_3.listing
+ , subq_3.user
+ , subq_3.listing__user
+ , subq_3.country_latest
+ , subq_3.is_lux_latest
+ , subq_3.capacity_latest
+ , subq_3.listing__country_latest
+ , subq_3.listing__is_lux_latest
+ , subq_3.listing__capacity_latest
+ , subq_3.listings
+ , subq_3.largest_listing
+ , subq_3.smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_3
+ ) subq_4
+ ) subq_5
+ ON
+ subq_2.listing = subq_5.listing
+ ) subq_6
+ ) subq_7
+ WHERE listing__is_lux_latest
+ ) subq_8
+ ) subq_9
+ GROUP BY
+ subq_9.metric_time__day
+ ) subq_10
+ ) subq_11
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_22.metric_time__day
+ , subq_22.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_21.metric_time__day
+ , SUM(subq_21.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_20.metric_time__day
+ , subq_20.bookings
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_19.metric_time__day
+ , subq_19.listing__is_lux_latest
+ , subq_19.bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'listing__is_lux_latest', 'metric_time__day']
+ SELECT
+ subq_18.metric_time__day
+ , subq_18.listing__is_lux_latest
+ , subq_18.bookings
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_14.metric_time__day AS metric_time__day
+ , subq_14.listing AS listing
+ , subq_17.is_lux_latest AS listing__is_lux_latest
+ , subq_14.bookings AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day', 'listing']
+ SELECT
+ subq_13.metric_time__day
+ , subq_13.listing
+ , subq_13.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_12.ds__day
+ , subq_12.ds__week
+ , subq_12.ds__month
+ , subq_12.ds__quarter
+ , subq_12.ds__year
+ , subq_12.ds__extract_year
+ , subq_12.ds__extract_quarter
+ , subq_12.ds__extract_month
+ , subq_12.ds__extract_day
+ , subq_12.ds__extract_dow
+ , subq_12.ds__extract_doy
+ , subq_12.ds_partitioned__day
+ , subq_12.ds_partitioned__week
+ , subq_12.ds_partitioned__month
+ , subq_12.ds_partitioned__quarter
+ , subq_12.ds_partitioned__year
+ , subq_12.ds_partitioned__extract_year
+ , subq_12.ds_partitioned__extract_quarter
+ , subq_12.ds_partitioned__extract_month
+ , subq_12.ds_partitioned__extract_day
+ , subq_12.ds_partitioned__extract_dow
+ , subq_12.ds_partitioned__extract_doy
+ , subq_12.paid_at__day
+ , subq_12.paid_at__week
+ , subq_12.paid_at__month
+ , subq_12.paid_at__quarter
+ , subq_12.paid_at__year
+ , subq_12.paid_at__extract_year
+ , subq_12.paid_at__extract_quarter
+ , subq_12.paid_at__extract_month
+ , subq_12.paid_at__extract_day
+ , subq_12.paid_at__extract_dow
+ , subq_12.paid_at__extract_doy
+ , subq_12.booking__ds__day
+ , subq_12.booking__ds__week
+ , subq_12.booking__ds__month
+ , subq_12.booking__ds__quarter
+ , subq_12.booking__ds__year
+ , subq_12.booking__ds__extract_year
+ , subq_12.booking__ds__extract_quarter
+ , subq_12.booking__ds__extract_month
+ , subq_12.booking__ds__extract_day
+ , subq_12.booking__ds__extract_dow
+ , subq_12.booking__ds__extract_doy
+ , subq_12.booking__ds_partitioned__day
+ , subq_12.booking__ds_partitioned__week
+ , subq_12.booking__ds_partitioned__month
+ , subq_12.booking__ds_partitioned__quarter
+ , subq_12.booking__ds_partitioned__year
+ , subq_12.booking__ds_partitioned__extract_year
+ , subq_12.booking__ds_partitioned__extract_quarter
+ , subq_12.booking__ds_partitioned__extract_month
+ , subq_12.booking__ds_partitioned__extract_day
+ , subq_12.booking__ds_partitioned__extract_dow
+ , subq_12.booking__ds_partitioned__extract_doy
+ , subq_12.booking__paid_at__day
+ , subq_12.booking__paid_at__week
+ , subq_12.booking__paid_at__month
+ , subq_12.booking__paid_at__quarter
+ , subq_12.booking__paid_at__year
+ , subq_12.booking__paid_at__extract_year
+ , subq_12.booking__paid_at__extract_quarter
+ , subq_12.booking__paid_at__extract_month
+ , subq_12.booking__paid_at__extract_day
+ , subq_12.booking__paid_at__extract_dow
+ , subq_12.booking__paid_at__extract_doy
+ , subq_12.ds__day AS metric_time__day
+ , subq_12.ds__week AS metric_time__week
+ , subq_12.ds__month AS metric_time__month
+ , subq_12.ds__quarter AS metric_time__quarter
+ , subq_12.ds__year AS metric_time__year
+ , subq_12.ds__extract_year AS metric_time__extract_year
+ , subq_12.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_12.ds__extract_month AS metric_time__extract_month
+ , subq_12.ds__extract_day AS metric_time__extract_day
+ , subq_12.ds__extract_dow AS metric_time__extract_dow
+ , subq_12.ds__extract_doy AS metric_time__extract_doy
+ , subq_12.listing
+ , subq_12.guest
+ , subq_12.host
+ , subq_12.booking__listing
+ , subq_12.booking__guest
+ , subq_12.booking__host
+ , subq_12.is_instant
+ , subq_12.booking__is_instant
+ , subq_12.bookings
+ , subq_12.instant_bookings
+ , subq_12.booking_value
+ , subq_12.max_booking_value
+ , subq_12.min_booking_value
+ , subq_12.bookers
+ , subq_12.average_booking_value
+ , subq_12.referred_bookings
+ , subq_12.median_booking_value
+ , subq_12.booking_value_p99
+ , subq_12.discrete_booking_value_p99
+ , subq_12.approximate_continuous_booking_value_p99
+ , subq_12.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_12
+ ) subq_13
+ ) subq_14
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['is_lux_latest', 'listing']
+ SELECT
+ subq_16.listing
+ , subq_16.is_lux_latest
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_15.ds__day
+ , subq_15.ds__week
+ , subq_15.ds__month
+ , subq_15.ds__quarter
+ , subq_15.ds__year
+ , subq_15.ds__extract_year
+ , subq_15.ds__extract_quarter
+ , subq_15.ds__extract_month
+ , subq_15.ds__extract_day
+ , subq_15.ds__extract_dow
+ , subq_15.ds__extract_doy
+ , subq_15.created_at__day
+ , subq_15.created_at__week
+ , subq_15.created_at__month
+ , subq_15.created_at__quarter
+ , subq_15.created_at__year
+ , subq_15.created_at__extract_year
+ , subq_15.created_at__extract_quarter
+ , subq_15.created_at__extract_month
+ , subq_15.created_at__extract_day
+ , subq_15.created_at__extract_dow
+ , subq_15.created_at__extract_doy
+ , subq_15.listing__ds__day
+ , subq_15.listing__ds__week
+ , subq_15.listing__ds__month
+ , subq_15.listing__ds__quarter
+ , subq_15.listing__ds__year
+ , subq_15.listing__ds__extract_year
+ , subq_15.listing__ds__extract_quarter
+ , subq_15.listing__ds__extract_month
+ , subq_15.listing__ds__extract_day
+ , subq_15.listing__ds__extract_dow
+ , subq_15.listing__ds__extract_doy
+ , subq_15.listing__created_at__day
+ , subq_15.listing__created_at__week
+ , subq_15.listing__created_at__month
+ , subq_15.listing__created_at__quarter
+ , subq_15.listing__created_at__year
+ , subq_15.listing__created_at__extract_year
+ , subq_15.listing__created_at__extract_quarter
+ , subq_15.listing__created_at__extract_month
+ , subq_15.listing__created_at__extract_day
+ , subq_15.listing__created_at__extract_dow
+ , subq_15.listing__created_at__extract_doy
+ , subq_15.ds__day AS metric_time__day
+ , subq_15.ds__week AS metric_time__week
+ , subq_15.ds__month AS metric_time__month
+ , subq_15.ds__quarter AS metric_time__quarter
+ , subq_15.ds__year AS metric_time__year
+ , subq_15.ds__extract_year AS metric_time__extract_year
+ , subq_15.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_15.ds__extract_month AS metric_time__extract_month
+ , subq_15.ds__extract_day AS metric_time__extract_day
+ , subq_15.ds__extract_dow AS metric_time__extract_dow
+ , subq_15.ds__extract_doy AS metric_time__extract_doy
+ , subq_15.listing
+ , subq_15.user
+ , subq_15.listing__user
+ , subq_15.country_latest
+ , subq_15.is_lux_latest
+ , subq_15.capacity_latest
+ , subq_15.listing__country_latest
+ , subq_15.listing__is_lux_latest
+ , subq_15.listing__capacity_latest
+ , subq_15.listings
+ , subq_15.largest_listing
+ , subq_15.smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_15
+ ) subq_16
+ ) subq_17
+ ON
+ subq_14.listing = subq_17.listing
+ ) subq_18
+ ) subq_19
+ WHERE listing__is_lux_latest
+ ) subq_20
+ ) subq_21
+ GROUP BY
+ subq_21.metric_time__day
+ ) subq_22
+ ) subq_23
+ ON
+ subq_11.metric_time__day = subq_23.metric_time__day
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_27.metric_time__day
+ , subq_27.booking_value
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_26.metric_time__day
+ , SUM(subq_26.booking_value) AS booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ SELECT
+ subq_25.metric_time__day
+ , subq_25.booking_value
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_24.ds__day
+ , subq_24.ds__week
+ , subq_24.ds__month
+ , subq_24.ds__quarter
+ , subq_24.ds__year
+ , subq_24.ds__extract_year
+ , subq_24.ds__extract_quarter
+ , subq_24.ds__extract_month
+ , subq_24.ds__extract_day
+ , subq_24.ds__extract_dow
+ , subq_24.ds__extract_doy
+ , subq_24.ds_partitioned__day
+ , subq_24.ds_partitioned__week
+ , subq_24.ds_partitioned__month
+ , subq_24.ds_partitioned__quarter
+ , subq_24.ds_partitioned__year
+ , subq_24.ds_partitioned__extract_year
+ , subq_24.ds_partitioned__extract_quarter
+ , subq_24.ds_partitioned__extract_month
+ , subq_24.ds_partitioned__extract_day
+ , subq_24.ds_partitioned__extract_dow
+ , subq_24.ds_partitioned__extract_doy
+ , subq_24.paid_at__day
+ , subq_24.paid_at__week
+ , subq_24.paid_at__month
+ , subq_24.paid_at__quarter
+ , subq_24.paid_at__year
+ , subq_24.paid_at__extract_year
+ , subq_24.paid_at__extract_quarter
+ , subq_24.paid_at__extract_month
+ , subq_24.paid_at__extract_day
+ , subq_24.paid_at__extract_dow
+ , subq_24.paid_at__extract_doy
+ , subq_24.booking__ds__day
+ , subq_24.booking__ds__week
+ , subq_24.booking__ds__month
+ , subq_24.booking__ds__quarter
+ , subq_24.booking__ds__year
+ , subq_24.booking__ds__extract_year
+ , subq_24.booking__ds__extract_quarter
+ , subq_24.booking__ds__extract_month
+ , subq_24.booking__ds__extract_day
+ , subq_24.booking__ds__extract_dow
+ , subq_24.booking__ds__extract_doy
+ , subq_24.booking__ds_partitioned__day
+ , subq_24.booking__ds_partitioned__week
+ , subq_24.booking__ds_partitioned__month
+ , subq_24.booking__ds_partitioned__quarter
+ , subq_24.booking__ds_partitioned__year
+ , subq_24.booking__ds_partitioned__extract_year
+ , subq_24.booking__ds_partitioned__extract_quarter
+ , subq_24.booking__ds_partitioned__extract_month
+ , subq_24.booking__ds_partitioned__extract_day
+ , subq_24.booking__ds_partitioned__extract_dow
+ , subq_24.booking__ds_partitioned__extract_doy
+ , subq_24.booking__paid_at__day
+ , subq_24.booking__paid_at__week
+ , subq_24.booking__paid_at__month
+ , subq_24.booking__paid_at__quarter
+ , subq_24.booking__paid_at__year
+ , subq_24.booking__paid_at__extract_year
+ , subq_24.booking__paid_at__extract_quarter
+ , subq_24.booking__paid_at__extract_month
+ , subq_24.booking__paid_at__extract_day
+ , subq_24.booking__paid_at__extract_dow
+ , subq_24.booking__paid_at__extract_doy
+ , subq_24.ds__day AS metric_time__day
+ , subq_24.ds__week AS metric_time__week
+ , subq_24.ds__month AS metric_time__month
+ , subq_24.ds__quarter AS metric_time__quarter
+ , subq_24.ds__year AS metric_time__year
+ , subq_24.ds__extract_year AS metric_time__extract_year
+ , subq_24.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_24.ds__extract_month AS metric_time__extract_month
+ , subq_24.ds__extract_day AS metric_time__extract_day
+ , subq_24.ds__extract_dow AS metric_time__extract_dow
+ , subq_24.ds__extract_doy AS metric_time__extract_doy
+ , subq_24.listing
+ , subq_24.guest
+ , subq_24.host
+ , subq_24.booking__listing
+ , subq_24.booking__guest
+ , subq_24.booking__host
+ , subq_24.is_instant
+ , subq_24.booking__is_instant
+ , subq_24.bookings
+ , subq_24.instant_bookings
+ , subq_24.booking_value
+ , subq_24.max_booking_value
+ , subq_24.min_booking_value
+ , subq_24.bookers
+ , subq_24.average_booking_value
+ , subq_24.referred_bookings
+ , subq_24.median_booking_value
+ , subq_24.booking_value_p99
+ , subq_24.discrete_booking_value_p99
+ , subq_24.approximate_continuous_booking_value_p99
+ , subq_24.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_24
+ ) subq_25
+ ) subq_26
+ GROUP BY
+ subq_26.metric_time__day
+ ) subq_27
+ ) subq_28
+ ON
+ COALESCE(subq_11.metric_time__day, subq_23.metric_time__day) = subq_28.metric_time__day
+ GROUP BY
+ COALESCE(subq_11.metric_time__day, subq_23.metric_time__day, subq_28.metric_time__day)
+) subq_29
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql
new file mode 100644
index 0000000000..5581a37a67
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint__plan0_optimized.sql
@@ -0,0 +1,96 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , average_booking_value * bookings / NULLIF(booking_value, 0) AS lux_booking_value_rate_expr
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_41.metric_time__day, subq_53.metric_time__day, subq_58.metric_time__day) AS metric_time__day
+ , MAX(subq_41.average_booking_value) AS average_booking_value
+ , MAX(subq_53.bookings) AS bookings
+ , MAX(subq_58.booking_value) AS booking_value
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements:
+ -- ['average_booking_value', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , AVG(average_booking_value) AS average_booking_value
+ FROM (
+ -- Join Standard Outputs
+ -- Pass Only Elements:
+ -- ['average_booking_value', 'listing__is_lux_latest', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', bookings_source_src_10001.ds) AS metric_time__day
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_10005
+ ON
+ bookings_source_src_10001.listing_id = listings_latest_src_10005.listing_id
+ ) subq_37
+ WHERE listing__is_lux_latest
+ GROUP BY
+ metric_time__day
+ ) subq_41
+ FULL OUTER JOIN (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Join Standard Outputs
+ -- Pass Only Elements:
+ -- ['bookings', 'listing__is_lux_latest', 'metric_time__day']
+ SELECT
+ subq_44.metric_time__day AS metric_time__day
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , subq_44.bookings AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day', 'listing']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , listing_id AS listing
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_44
+ LEFT OUTER JOIN
+ ***************************.dim_listings_latest listings_latest_src_10005
+ ON
+ subq_44.listing = listings_latest_src_10005.listing_id
+ ) subq_49
+ WHERE listing__is_lux_latest
+ GROUP BY
+ metric_time__day
+ ) subq_53
+ ON
+ subq_41.metric_time__day = subq_53.metric_time__day
+ FULL OUTER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , SUM(booking_value) AS booking_value
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ GROUP BY
+ DATE_TRUNC('day', ds)
+ ) subq_58
+ ON
+ COALESCE(subq_41.metric_time__day, subq_53.metric_time__day) = subq_58.metric_time__day
+ GROUP BY
+ COALESCE(subq_41.metric_time__day, subq_53.metric_time__day, subq_58.metric_time__day)
+) subq_59
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql
new file mode 100644
index 0000000000..81907f7e40
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0.sql
@@ -0,0 +1,463 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_12.metric_time__day
+ , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day
+ , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint
+ , MAX(subq_11.booking_value) AS booking_value
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_5.metric_time__day
+ , subq_5.booking_value AS booking_value_with_is_instant_constraint
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_4.metric_time__day
+ , SUM(subq_4.booking_value) AS booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.booking_value
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.booking__is_instant
+ , subq_2.booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_value', 'booking__is_instant', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.booking__is_instant
+ , subq_1.booking_value
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ WHERE booking__is_instant
+ ) subq_3
+ ) subq_4
+ GROUP BY
+ subq_4.metric_time__day
+ ) subq_5
+ ) subq_6
+ FULL OUTER JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_10.metric_time__day
+ , subq_10.booking_value
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_9.metric_time__day
+ , SUM(subq_9.booking_value) AS booking_value
+ FROM (
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ SELECT
+ subq_8.metric_time__day
+ , subq_8.booking_value
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.ds_partitioned__day
+ , subq_7.ds_partitioned__week
+ , subq_7.ds_partitioned__month
+ , subq_7.ds_partitioned__quarter
+ , subq_7.ds_partitioned__year
+ , subq_7.ds_partitioned__extract_year
+ , subq_7.ds_partitioned__extract_quarter
+ , subq_7.ds_partitioned__extract_month
+ , subq_7.ds_partitioned__extract_day
+ , subq_7.ds_partitioned__extract_dow
+ , subq_7.ds_partitioned__extract_doy
+ , subq_7.paid_at__day
+ , subq_7.paid_at__week
+ , subq_7.paid_at__month
+ , subq_7.paid_at__quarter
+ , subq_7.paid_at__year
+ , subq_7.paid_at__extract_year
+ , subq_7.paid_at__extract_quarter
+ , subq_7.paid_at__extract_month
+ , subq_7.paid_at__extract_day
+ , subq_7.paid_at__extract_dow
+ , subq_7.paid_at__extract_doy
+ , subq_7.booking__ds__day
+ , subq_7.booking__ds__week
+ , subq_7.booking__ds__month
+ , subq_7.booking__ds__quarter
+ , subq_7.booking__ds__year
+ , subq_7.booking__ds__extract_year
+ , subq_7.booking__ds__extract_quarter
+ , subq_7.booking__ds__extract_month
+ , subq_7.booking__ds__extract_day
+ , subq_7.booking__ds__extract_dow
+ , subq_7.booking__ds__extract_doy
+ , subq_7.booking__ds_partitioned__day
+ , subq_7.booking__ds_partitioned__week
+ , subq_7.booking__ds_partitioned__month
+ , subq_7.booking__ds_partitioned__quarter
+ , subq_7.booking__ds_partitioned__year
+ , subq_7.booking__ds_partitioned__extract_year
+ , subq_7.booking__ds_partitioned__extract_quarter
+ , subq_7.booking__ds_partitioned__extract_month
+ , subq_7.booking__ds_partitioned__extract_day
+ , subq_7.booking__ds_partitioned__extract_dow
+ , subq_7.booking__ds_partitioned__extract_doy
+ , subq_7.booking__paid_at__day
+ , subq_7.booking__paid_at__week
+ , subq_7.booking__paid_at__month
+ , subq_7.booking__paid_at__quarter
+ , subq_7.booking__paid_at__year
+ , subq_7.booking__paid_at__extract_year
+ , subq_7.booking__paid_at__extract_quarter
+ , subq_7.booking__paid_at__extract_month
+ , subq_7.booking__paid_at__extract_day
+ , subq_7.booking__paid_at__extract_dow
+ , subq_7.booking__paid_at__extract_doy
+ , subq_7.ds__day AS metric_time__day
+ , subq_7.ds__week AS metric_time__week
+ , subq_7.ds__month AS metric_time__month
+ , subq_7.ds__quarter AS metric_time__quarter
+ , subq_7.ds__year AS metric_time__year
+ , subq_7.ds__extract_year AS metric_time__extract_year
+ , subq_7.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_7.ds__extract_month AS metric_time__extract_month
+ , subq_7.ds__extract_day AS metric_time__extract_day
+ , subq_7.ds__extract_dow AS metric_time__extract_dow
+ , subq_7.ds__extract_doy AS metric_time__extract_doy
+ , subq_7.listing
+ , subq_7.guest
+ , subq_7.host
+ , subq_7.booking__listing
+ , subq_7.booking__guest
+ , subq_7.booking__host
+ , subq_7.is_instant
+ , subq_7.booking__is_instant
+ , subq_7.bookings
+ , subq_7.instant_bookings
+ , subq_7.booking_value
+ , subq_7.max_booking_value
+ , subq_7.min_booking_value
+ , subq_7.bookers
+ , subq_7.average_booking_value
+ , subq_7.referred_bookings
+ , subq_7.median_booking_value
+ , subq_7.booking_value_p99
+ , subq_7.discrete_booking_value_p99
+ , subq_7.approximate_continuous_booking_value_p99
+ , subq_7.approximate_discrete_booking_value_p99
+ 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_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_7
+ ) subq_8
+ ) subq_9
+ GROUP BY
+ subq_9.metric_time__day
+ ) subq_10
+ ) subq_11
+ ON
+ subq_6.metric_time__day = subq_11.metric_time__day
+ GROUP BY
+ COALESCE(subq_6.metric_time__day, subq_11.metric_time__day)
+) subq_12
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql
new file mode 100644
index 0000000000..2d2b5a142c
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_reused_measure__plan0_optimized.sql
@@ -0,0 +1,53 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , CAST(booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day
+ , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint
+ , MAX(subq_24.booking_value) AS booking_value
+ FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(booking_value) AS booking_value_with_is_instant_constraint
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['booking_value', 'booking__is_instant', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , is_instant AS booking__is_instant
+ , booking_value
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_15
+ WHERE booking__is_instant
+ GROUP BY
+ metric_time__day
+ ) subq_19
+ FULL OUTER JOIN (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['booking_value', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , SUM(booking_value) AS booking_value
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ GROUP BY
+ DATE_TRUNC('day', ds)
+ ) subq_24
+ ON
+ subq_19.metric_time__day = subq_24.metric_time__day
+ GROUP BY
+ COALESCE(subq_19.metric_time__day, subq_24.metric_time__day)
+) subq_25
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql
new file mode 100644
index 0000000000..f1e61da6cd
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0.sql
@@ -0,0 +1,236 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_6.metric_time__day
+ , delayed_bookings * 2 AS double_counted_delayed_bookings
+FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_5.metric_time__day
+ , subq_5.bookings AS delayed_bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_4.metric_time__day
+ , SUM(subq_4.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_3.metric_time__day
+ , subq_3.bookings
+ FROM (
+ -- Constrain Output with WHERE
+ SELECT
+ subq_2.metric_time__day
+ , subq_2.booking__is_instant
+ , subq_2.bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__is_instant', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.booking__is_instant
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ WHERE NOT booking__is_instant
+ ) subq_3
+ ) subq_4
+ GROUP BY
+ subq_4.metric_time__day
+ ) subq_5
+) subq_6
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql
new file mode 100644
index 0000000000..18094198a4
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql
@@ -0,0 +1,28 @@
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , delayed_bookings * 2 AS double_counted_delayed_bookings
+FROM (
+ -- Constrain Output with WHERE
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS delayed_bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'booking__is_instant', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , is_instant AS booking__is_instant
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_9
+ WHERE NOT booking__is_instant
+ GROUP BY
+ metric_time__day
+) subq_13
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql
new file mode 100644
index 0000000000..cbc1f426c2
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql
@@ -0,0 +1,368 @@
+-- Compute Metrics via Expressions
+SELECT
+ CAST(subq_10.bookings AS DOUBLE) / CAST(NULLIF(subq_10.listings, 0) AS DOUBLE) AS bookings_per_listing
+FROM (
+ -- Combine Aggregated Outputs
+ SELECT
+ MAX(subq_4.bookings) AS bookings
+ , MAX(subq_9.listings) AS listings
+ FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_3.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings']
+ SELECT
+ subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ ) subq_3
+ ) subq_4
+ CROSS JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_8.listings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_7.listings) AS listings
+ FROM (
+ -- Pass Only Elements:
+ -- ['listings']
+ SELECT
+ subq_6.listings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_5.ds__day
+ , subq_5.ds__week
+ , subq_5.ds__month
+ , subq_5.ds__quarter
+ , subq_5.ds__year
+ , subq_5.ds__extract_year
+ , subq_5.ds__extract_quarter
+ , subq_5.ds__extract_month
+ , subq_5.ds__extract_day
+ , subq_5.ds__extract_dow
+ , subq_5.ds__extract_doy
+ , subq_5.created_at__day
+ , subq_5.created_at__week
+ , subq_5.created_at__month
+ , subq_5.created_at__quarter
+ , subq_5.created_at__year
+ , subq_5.created_at__extract_year
+ , subq_5.created_at__extract_quarter
+ , subq_5.created_at__extract_month
+ , subq_5.created_at__extract_day
+ , subq_5.created_at__extract_dow
+ , subq_5.created_at__extract_doy
+ , subq_5.listing__ds__day
+ , subq_5.listing__ds__week
+ , subq_5.listing__ds__month
+ , subq_5.listing__ds__quarter
+ , subq_5.listing__ds__year
+ , subq_5.listing__ds__extract_year
+ , subq_5.listing__ds__extract_quarter
+ , subq_5.listing__ds__extract_month
+ , subq_5.listing__ds__extract_day
+ , subq_5.listing__ds__extract_dow
+ , subq_5.listing__ds__extract_doy
+ , subq_5.listing__created_at__day
+ , subq_5.listing__created_at__week
+ , subq_5.listing__created_at__month
+ , subq_5.listing__created_at__quarter
+ , subq_5.listing__created_at__year
+ , subq_5.listing__created_at__extract_year
+ , subq_5.listing__created_at__extract_quarter
+ , subq_5.listing__created_at__extract_month
+ , subq_5.listing__created_at__extract_day
+ , subq_5.listing__created_at__extract_dow
+ , subq_5.listing__created_at__extract_doy
+ , subq_5.ds__day AS metric_time__day
+ , subq_5.ds__week AS metric_time__week
+ , subq_5.ds__month AS metric_time__month
+ , subq_5.ds__quarter AS metric_time__quarter
+ , subq_5.ds__year AS metric_time__year
+ , subq_5.ds__extract_year AS metric_time__extract_year
+ , subq_5.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_5.ds__extract_month AS metric_time__extract_month
+ , subq_5.ds__extract_day AS metric_time__extract_day
+ , subq_5.ds__extract_dow AS metric_time__extract_dow
+ , subq_5.ds__extract_doy AS metric_time__extract_doy
+ , subq_5.listing
+ , subq_5.user
+ , subq_5.listing__user
+ , subq_5.country_latest
+ , subq_5.is_lux_latest
+ , subq_5.capacity_latest
+ , subq_5.listing__country_latest
+ , subq_5.listing__is_lux_latest
+ , subq_5.listing__capacity_latest
+ , subq_5.listings
+ , subq_5.largest_listing
+ , subq_5.smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_5
+ ) subq_6
+ ) subq_7
+ ) subq_8
+ ) subq_9
+) subq_10
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql
new file mode 100644
index 0000000000..1e16df6c0d
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql
@@ -0,0 +1,26 @@
+-- Combine Aggregated Outputs
+-- Compute Metrics via Expressions
+SELECT
+ CAST(MAX(subq_15.bookings) AS DOUBLE) / CAST(NULLIF(MAX(subq_20.listings), 0) AS DOUBLE) AS bookings_per_listing
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ SUM(1) AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+) subq_15
+CROSS JOIN (
+ -- Read Elements From Semantic Model 'listings_latest'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['listings']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ SUM(1) AS listings
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+) subq_20
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql
new file mode 100644
index 0000000000..2bbff5684b
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0.sql
@@ -0,0 +1,460 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_10.metric_time__day
+ , subq_10.listing__user__home_state_latest
+ , subq_10.bookings
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_9.metric_time__day
+ , subq_9.listing__user__home_state_latest
+ , SUM(subq_9.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'listing__user__home_state_latest', 'metric_time__day']
+ SELECT
+ subq_8.metric_time__day
+ , subq_8.listing__user__home_state_latest
+ , subq_8.bookings
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , subq_7.window_start__day AS listing__window_start__day
+ , subq_7.window_end__day AS listing__window_end__day
+ , subq_2.listing AS listing
+ , subq_7.user__home_state_latest AS listing__user__home_state_latest
+ , subq_2.bookings AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day', 'listing']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.listing
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.user
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.booking__user
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ 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_10017.booking_value
+ , bookings_source_src_10017.guest_id AS bookers
+ , bookings_source_src_10017.booking_value AS average_booking_value
+ , bookings_source_src_10017.booking_value AS booking_payments
+ , bookings_source_src_10017.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10017.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10017.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10017.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10017.listing_id AS listing
+ , bookings_source_src_10017.guest_id AS guest
+ , bookings_source_src_10017.host_id AS host
+ , bookings_source_src_10017.guest_id AS user
+ , bookings_source_src_10017.listing_id AS booking__listing
+ , bookings_source_src_10017.guest_id AS booking__guest
+ , bookings_source_src_10017.host_id AS booking__host
+ , bookings_source_src_10017.guest_id AS booking__user
+ FROM ***************************.fct_bookings bookings_source_src_10017
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing']
+ SELECT
+ subq_6.window_start__day
+ , subq_6.window_end__day
+ , subq_6.listing
+ , subq_6.user__home_state_latest
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_3.window_start__day AS window_start__day
+ , subq_3.window_start__week AS window_start__week
+ , subq_3.window_start__month AS window_start__month
+ , subq_3.window_start__quarter AS window_start__quarter
+ , subq_3.window_start__year AS window_start__year
+ , subq_3.window_start__extract_year AS window_start__extract_year
+ , subq_3.window_start__extract_quarter AS window_start__extract_quarter
+ , subq_3.window_start__extract_month AS window_start__extract_month
+ , subq_3.window_start__extract_day AS window_start__extract_day
+ , subq_3.window_start__extract_dow AS window_start__extract_dow
+ , subq_3.window_start__extract_doy AS window_start__extract_doy
+ , subq_3.window_end__day AS window_end__day
+ , subq_3.window_end__week AS window_end__week
+ , subq_3.window_end__month AS window_end__month
+ , subq_3.window_end__quarter AS window_end__quarter
+ , subq_3.window_end__year AS window_end__year
+ , subq_3.window_end__extract_year AS window_end__extract_year
+ , subq_3.window_end__extract_quarter AS window_end__extract_quarter
+ , subq_3.window_end__extract_month AS window_end__extract_month
+ , subq_3.window_end__extract_day AS window_end__extract_day
+ , subq_3.window_end__extract_dow AS window_end__extract_dow
+ , subq_3.window_end__extract_doy AS window_end__extract_doy
+ , subq_3.listing__window_start__day AS listing__window_start__day
+ , subq_3.listing__window_start__week AS listing__window_start__week
+ , subq_3.listing__window_start__month AS listing__window_start__month
+ , subq_3.listing__window_start__quarter AS listing__window_start__quarter
+ , subq_3.listing__window_start__year AS listing__window_start__year
+ , subq_3.listing__window_start__extract_year AS listing__window_start__extract_year
+ , subq_3.listing__window_start__extract_quarter AS listing__window_start__extract_quarter
+ , subq_3.listing__window_start__extract_month AS listing__window_start__extract_month
+ , subq_3.listing__window_start__extract_day AS listing__window_start__extract_day
+ , subq_3.listing__window_start__extract_dow AS listing__window_start__extract_dow
+ , subq_3.listing__window_start__extract_doy AS listing__window_start__extract_doy
+ , subq_3.listing__window_end__day AS listing__window_end__day
+ , subq_3.listing__window_end__week AS listing__window_end__week
+ , subq_3.listing__window_end__month AS listing__window_end__month
+ , subq_3.listing__window_end__quarter AS listing__window_end__quarter
+ , subq_3.listing__window_end__year AS listing__window_end__year
+ , subq_3.listing__window_end__extract_year AS listing__window_end__extract_year
+ , subq_3.listing__window_end__extract_quarter AS listing__window_end__extract_quarter
+ , subq_3.listing__window_end__extract_month AS listing__window_end__extract_month
+ , subq_3.listing__window_end__extract_day AS listing__window_end__extract_day
+ , subq_3.listing__window_end__extract_dow AS listing__window_end__extract_dow
+ , subq_3.listing__window_end__extract_doy AS listing__window_end__extract_doy
+ , subq_5.ds__day AS user__ds__day
+ , subq_5.ds__week AS user__ds__week
+ , subq_5.ds__month AS user__ds__month
+ , subq_5.ds__quarter AS user__ds__quarter
+ , subq_5.ds__year AS user__ds__year
+ , subq_5.ds__extract_year AS user__ds__extract_year
+ , subq_5.ds__extract_quarter AS user__ds__extract_quarter
+ , subq_5.ds__extract_month AS user__ds__extract_month
+ , subq_5.ds__extract_day AS user__ds__extract_day
+ , subq_5.ds__extract_dow AS user__ds__extract_dow
+ , subq_5.ds__extract_doy AS user__ds__extract_doy
+ , subq_3.listing AS listing
+ , subq_3.user AS user
+ , subq_3.listing__user AS listing__user
+ , subq_3.country AS country
+ , subq_3.is_lux AS is_lux
+ , subq_3.capacity AS capacity
+ , subq_3.listing__country AS listing__country
+ , subq_3.listing__is_lux AS listing__is_lux
+ , subq_3.listing__capacity AS listing__capacity
+ , subq_5.home_state_latest AS user__home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'listings'
+ SELECT
+ listings_src_10019.active_from AS window_start__day
+ , DATE_TRUNC('week', listings_src_10019.active_from) AS window_start__week
+ , DATE_TRUNC('month', listings_src_10019.active_from) AS window_start__month
+ , DATE_TRUNC('quarter', listings_src_10019.active_from) AS window_start__quarter
+ , DATE_TRUNC('year', listings_src_10019.active_from) AS window_start__year
+ , EXTRACT(year FROM listings_src_10019.active_from) AS window_start__extract_year
+ , EXTRACT(quarter FROM listings_src_10019.active_from) AS window_start__extract_quarter
+ , EXTRACT(month FROM listings_src_10019.active_from) AS window_start__extract_month
+ , EXTRACT(day FROM listings_src_10019.active_from) AS window_start__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_from) AS window_start__extract_dow
+ , EXTRACT(doy FROM listings_src_10019.active_from) AS window_start__extract_doy
+ , listings_src_10019.active_to AS window_end__day
+ , DATE_TRUNC('week', listings_src_10019.active_to) AS window_end__week
+ , DATE_TRUNC('month', listings_src_10019.active_to) AS window_end__month
+ , DATE_TRUNC('quarter', listings_src_10019.active_to) AS window_end__quarter
+ , DATE_TRUNC('year', listings_src_10019.active_to) AS window_end__year
+ , EXTRACT(year FROM listings_src_10019.active_to) AS window_end__extract_year
+ , EXTRACT(quarter FROM listings_src_10019.active_to) AS window_end__extract_quarter
+ , EXTRACT(month FROM listings_src_10019.active_to) AS window_end__extract_month
+ , EXTRACT(day FROM listings_src_10019.active_to) AS window_end__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_to) AS window_end__extract_dow
+ , EXTRACT(doy FROM listings_src_10019.active_to) AS window_end__extract_doy
+ , listings_src_10019.country
+ , listings_src_10019.is_lux
+ , listings_src_10019.capacity
+ , listings_src_10019.active_from AS listing__window_start__day
+ , DATE_TRUNC('week', listings_src_10019.active_from) AS listing__window_start__week
+ , DATE_TRUNC('month', listings_src_10019.active_from) AS listing__window_start__month
+ , DATE_TRUNC('quarter', listings_src_10019.active_from) AS listing__window_start__quarter
+ , DATE_TRUNC('year', listings_src_10019.active_from) AS listing__window_start__year
+ , EXTRACT(year FROM listings_src_10019.active_from) AS listing__window_start__extract_year
+ , EXTRACT(quarter FROM listings_src_10019.active_from) AS listing__window_start__extract_quarter
+ , EXTRACT(month FROM listings_src_10019.active_from) AS listing__window_start__extract_month
+ , EXTRACT(day FROM listings_src_10019.active_from) AS listing__window_start__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_from) AS listing__window_start__extract_dow
+ , EXTRACT(doy FROM listings_src_10019.active_from) AS listing__window_start__extract_doy
+ , listings_src_10019.active_to AS listing__window_end__day
+ , DATE_TRUNC('week', listings_src_10019.active_to) AS listing__window_end__week
+ , DATE_TRUNC('month', listings_src_10019.active_to) AS listing__window_end__month
+ , DATE_TRUNC('quarter', listings_src_10019.active_to) AS listing__window_end__quarter
+ , DATE_TRUNC('year', listings_src_10019.active_to) AS listing__window_end__year
+ , EXTRACT(year FROM listings_src_10019.active_to) AS listing__window_end__extract_year
+ , EXTRACT(quarter FROM listings_src_10019.active_to) AS listing__window_end__extract_quarter
+ , EXTRACT(month FROM listings_src_10019.active_to) AS listing__window_end__extract_month
+ , EXTRACT(day FROM listings_src_10019.active_to) AS listing__window_end__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_src_10019.active_to) AS listing__window_end__extract_dow
+ , EXTRACT(doy FROM listings_src_10019.active_to) AS listing__window_end__extract_doy
+ , listings_src_10019.country AS listing__country
+ , listings_src_10019.is_lux AS listing__is_lux
+ , listings_src_10019.capacity AS listing__capacity
+ , listings_src_10019.listing_id AS listing
+ , listings_src_10019.user_id AS user
+ , listings_src_10019.user_id AS listing__user
+ FROM ***************************.dim_listings listings_src_10019
+ ) subq_3
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['home_state_latest',
+ -- 'user__home_state_latest',
+ -- 'ds__day',
+ -- 'ds__week',
+ -- 'ds__month',
+ -- 'ds__quarter',
+ -- 'ds__year',
+ -- 'ds__extract_year',
+ -- 'ds__extract_quarter',
+ -- 'ds__extract_month',
+ -- 'ds__extract_day',
+ -- 'ds__extract_dow',
+ -- 'ds__extract_doy',
+ -- 'user__ds__day',
+ -- 'user__ds__week',
+ -- 'user__ds__month',
+ -- 'user__ds__quarter',
+ -- 'user__ds__year',
+ -- 'user__ds__extract_year',
+ -- 'user__ds__extract_quarter',
+ -- 'user__ds__extract_month',
+ -- 'user__ds__extract_day',
+ -- 'user__ds__extract_dow',
+ -- 'user__ds__extract_doy',
+ -- 'user']
+ SELECT
+ subq_4.ds__day
+ , subq_4.ds__week
+ , subq_4.ds__month
+ , subq_4.ds__quarter
+ , subq_4.ds__year
+ , subq_4.ds__extract_year
+ , subq_4.ds__extract_quarter
+ , subq_4.ds__extract_month
+ , subq_4.ds__extract_day
+ , subq_4.ds__extract_dow
+ , subq_4.ds__extract_doy
+ , subq_4.user__ds__day
+ , subq_4.user__ds__week
+ , subq_4.user__ds__month
+ , subq_4.user__ds__quarter
+ , subq_4.user__ds__year
+ , subq_4.user__ds__extract_year
+ , subq_4.user__ds__extract_quarter
+ , subq_4.user__ds__extract_month
+ , subq_4.user__ds__extract_day
+ , subq_4.user__ds__extract_dow
+ , subq_4.user__ds__extract_doy
+ , subq_4.user
+ , subq_4.home_state_latest
+ , subq_4.user__home_state_latest
+ FROM (
+ -- Read Elements From Semantic Model 'users_latest'
+ SELECT
+ DATE_TRUNC('day', users_latest_src_10023.ds) AS ds__day
+ , DATE_TRUNC('week', users_latest_src_10023.ds) AS ds__week
+ , DATE_TRUNC('month', users_latest_src_10023.ds) AS ds__month
+ , DATE_TRUNC('quarter', users_latest_src_10023.ds) AS ds__quarter
+ , DATE_TRUNC('year', users_latest_src_10023.ds) AS ds__year
+ , EXTRACT(year FROM users_latest_src_10023.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10023.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10023.ds) AS ds__extract_month
+ , EXTRACT(day FROM users_latest_src_10023.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10023.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10023.ds) AS ds__extract_doy
+ , users_latest_src_10023.home_state_latest
+ , DATE_TRUNC('day', users_latest_src_10023.ds) AS user__ds__day
+ , DATE_TRUNC('week', users_latest_src_10023.ds) AS user__ds__week
+ , DATE_TRUNC('month', users_latest_src_10023.ds) AS user__ds__month
+ , DATE_TRUNC('quarter', users_latest_src_10023.ds) AS user__ds__quarter
+ , DATE_TRUNC('year', users_latest_src_10023.ds) AS user__ds__year
+ , EXTRACT(year FROM users_latest_src_10023.ds) AS user__ds__extract_year
+ , EXTRACT(quarter FROM users_latest_src_10023.ds) AS user__ds__extract_quarter
+ , EXTRACT(month FROM users_latest_src_10023.ds) AS user__ds__extract_month
+ , EXTRACT(day FROM users_latest_src_10023.ds) AS user__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_latest_src_10023.ds) AS user__ds__extract_dow
+ , EXTRACT(doy FROM users_latest_src_10023.ds) AS user__ds__extract_doy
+ , users_latest_src_10023.home_state_latest AS user__home_state_latest
+ , users_latest_src_10023.user_id AS user
+ FROM ***************************.dim_users_latest users_latest_src_10023
+ ) subq_4
+ ) subq_5
+ ON
+ subq_3.user = subq_5.user
+ ) subq_6
+ ) subq_7
+ ON
+ (
+ subq_2.listing = subq_7.listing
+ ) AND (
+ (
+ subq_2.metric_time__day >= subq_7.window_start__day
+ ) AND (
+ (
+ subq_2.metric_time__day < subq_7.window_end__day
+ ) OR (
+ subq_7.window_end__day IS NULL
+ )
+ )
+ )
+ ) subq_8
+ ) subq_9
+ GROUP BY
+ subq_9.metric_time__day
+ , subq_9.listing__user__home_state_latest
+) subq_10
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql
new file mode 100644
index 0000000000..afba0439d0
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_through_scd_dimension__plan0_optimized.sql
@@ -0,0 +1,52 @@
+-- Join Standard Outputs
+-- Pass Only Elements:
+-- ['bookings', 'listing__user__home_state_latest', 'metric_time__day']
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ subq_13.metric_time__day AS metric_time__day
+ , subq_18.user__home_state_latest AS listing__user__home_state_latest
+ , SUM(subq_13.bookings) AS bookings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day', 'listing']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , listing_id AS listing
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10017
+) subq_13
+LEFT OUTER JOIN (
+ -- Join Standard Outputs
+ -- Pass Only Elements:
+ -- ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing']
+ SELECT
+ listings_src_10019.active_from AS window_start__day
+ , listings_src_10019.active_to AS window_end__day
+ , listings_src_10019.listing_id AS listing
+ , users_latest_src_10023.home_state_latest AS user__home_state_latest
+ FROM ***************************.dim_listings listings_src_10019
+ LEFT OUTER JOIN
+ ***************************.dim_users_latest users_latest_src_10023
+ ON
+ listings_src_10019.user_id = users_latest_src_10023.user_id
+) subq_18
+ON
+ (
+ subq_13.listing = subq_18.listing
+ ) AND (
+ (
+ subq_13.metric_time__day >= subq_18.window_start__day
+ ) AND (
+ (
+ subq_13.metric_time__day < subq_18.window_end__day
+ ) OR (
+ subq_18.window_end__day IS NULL
+ )
+ )
+ )
+GROUP BY
+ subq_13.metric_time__day
+ , subq_18.user__home_state_latest
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql
new file mode 100644
index 0000000000..5e879e0c1c
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0.sql
@@ -0,0 +1,440 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_10.metric_time__day
+ , subq_10.listing__lux_listing__is_confirmed_lux
+ , subq_10.bookings
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_9.metric_time__day
+ , subq_9.listing__lux_listing__is_confirmed_lux
+ , SUM(subq_9.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'listing__lux_listing__is_confirmed_lux', 'metric_time__day']
+ SELECT
+ subq_8.metric_time__day
+ , subq_8.listing__lux_listing__is_confirmed_lux
+ , subq_8.bookings
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_2.metric_time__day AS metric_time__day
+ , subq_7.lux_listing__window_start__day AS listing__lux_listing__window_start__day
+ , subq_7.lux_listing__window_end__day AS listing__lux_listing__window_end__day
+ , subq_2.listing AS listing
+ , subq_7.lux_listing__is_confirmed_lux AS listing__lux_listing__is_confirmed_lux
+ , subq_2.bookings AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day', 'listing']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.listing
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.user
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.booking__user
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ 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_10017.booking_value
+ , bookings_source_src_10017.guest_id AS bookers
+ , bookings_source_src_10017.booking_value AS average_booking_value
+ , bookings_source_src_10017.booking_value AS booking_payments
+ , bookings_source_src_10017.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10017.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10017.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10017.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10017.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10017.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10017.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10017.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10017.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10017.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10017.listing_id AS listing
+ , bookings_source_src_10017.guest_id AS guest
+ , bookings_source_src_10017.host_id AS host
+ , bookings_source_src_10017.guest_id AS user
+ , bookings_source_src_10017.listing_id AS booking__listing
+ , bookings_source_src_10017.guest_id AS booking__guest
+ , bookings_source_src_10017.host_id AS booking__host
+ , bookings_source_src_10017.guest_id AS booking__user
+ FROM ***************************.fct_bookings bookings_source_src_10017
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['lux_listing__is_confirmed_lux',
+ -- 'lux_listing__window_start__day',
+ -- 'lux_listing__window_end__day',
+ -- 'listing']
+ SELECT
+ subq_6.lux_listing__window_start__day
+ , subq_6.lux_listing__window_end__day
+ , subq_6.listing
+ , subq_6.lux_listing__is_confirmed_lux
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_5.window_start__day AS lux_listing__window_start__day
+ , subq_5.window_start__week AS lux_listing__window_start__week
+ , subq_5.window_start__month AS lux_listing__window_start__month
+ , subq_5.window_start__quarter AS lux_listing__window_start__quarter
+ , subq_5.window_start__year AS lux_listing__window_start__year
+ , subq_5.window_start__extract_year AS lux_listing__window_start__extract_year
+ , subq_5.window_start__extract_quarter AS lux_listing__window_start__extract_quarter
+ , subq_5.window_start__extract_month AS lux_listing__window_start__extract_month
+ , subq_5.window_start__extract_day AS lux_listing__window_start__extract_day
+ , subq_5.window_start__extract_dow AS lux_listing__window_start__extract_dow
+ , subq_5.window_start__extract_doy AS lux_listing__window_start__extract_doy
+ , subq_5.window_end__day AS lux_listing__window_end__day
+ , subq_5.window_end__week AS lux_listing__window_end__week
+ , subq_5.window_end__month AS lux_listing__window_end__month
+ , subq_5.window_end__quarter AS lux_listing__window_end__quarter
+ , subq_5.window_end__year AS lux_listing__window_end__year
+ , subq_5.window_end__extract_year AS lux_listing__window_end__extract_year
+ , subq_5.window_end__extract_quarter AS lux_listing__window_end__extract_quarter
+ , subq_5.window_end__extract_month AS lux_listing__window_end__extract_month
+ , subq_5.window_end__extract_day AS lux_listing__window_end__extract_day
+ , subq_5.window_end__extract_dow AS lux_listing__window_end__extract_dow
+ , subq_5.window_end__extract_doy AS lux_listing__window_end__extract_doy
+ , subq_3.listing AS listing
+ , subq_3.lux_listing AS lux_listing
+ , subq_3.listing__lux_listing AS listing__lux_listing
+ , subq_5.is_confirmed_lux AS lux_listing__is_confirmed_lux
+ FROM (
+ -- Read Elements From Semantic Model 'lux_listing_mapping'
+ SELECT
+ lux_listing_mapping_src_10020.listing_id AS listing
+ , lux_listing_mapping_src_10020.lux_listing_id AS lux_listing
+ , lux_listing_mapping_src_10020.lux_listing_id AS listing__lux_listing
+ FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_10020
+ ) subq_3
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['is_confirmed_lux',
+ -- 'lux_listing__is_confirmed_lux',
+ -- 'window_start__day',
+ -- 'window_start__week',
+ -- 'window_start__month',
+ -- 'window_start__quarter',
+ -- 'window_start__year',
+ -- 'window_start__extract_year',
+ -- 'window_start__extract_quarter',
+ -- 'window_start__extract_month',
+ -- 'window_start__extract_day',
+ -- 'window_start__extract_dow',
+ -- 'window_start__extract_doy',
+ -- 'window_end__day',
+ -- 'window_end__week',
+ -- 'window_end__month',
+ -- 'window_end__quarter',
+ -- 'window_end__year',
+ -- 'window_end__extract_year',
+ -- 'window_end__extract_quarter',
+ -- 'window_end__extract_month',
+ -- 'window_end__extract_day',
+ -- 'window_end__extract_dow',
+ -- 'window_end__extract_doy',
+ -- 'lux_listing__window_start__day',
+ -- 'lux_listing__window_start__week',
+ -- 'lux_listing__window_start__month',
+ -- 'lux_listing__window_start__quarter',
+ -- 'lux_listing__window_start__year',
+ -- 'lux_listing__window_start__extract_year',
+ -- 'lux_listing__window_start__extract_quarter',
+ -- 'lux_listing__window_start__extract_month',
+ -- 'lux_listing__window_start__extract_day',
+ -- 'lux_listing__window_start__extract_dow',
+ -- 'lux_listing__window_start__extract_doy',
+ -- 'lux_listing__window_end__day',
+ -- 'lux_listing__window_end__week',
+ -- 'lux_listing__window_end__month',
+ -- 'lux_listing__window_end__quarter',
+ -- 'lux_listing__window_end__year',
+ -- 'lux_listing__window_end__extract_year',
+ -- 'lux_listing__window_end__extract_quarter',
+ -- 'lux_listing__window_end__extract_month',
+ -- 'lux_listing__window_end__extract_day',
+ -- 'lux_listing__window_end__extract_dow',
+ -- 'lux_listing__window_end__extract_doy',
+ -- 'lux_listing']
+ SELECT
+ subq_4.window_start__day
+ , subq_4.window_start__week
+ , subq_4.window_start__month
+ , subq_4.window_start__quarter
+ , subq_4.window_start__year
+ , subq_4.window_start__extract_year
+ , subq_4.window_start__extract_quarter
+ , subq_4.window_start__extract_month
+ , subq_4.window_start__extract_day
+ , subq_4.window_start__extract_dow
+ , subq_4.window_start__extract_doy
+ , subq_4.window_end__day
+ , subq_4.window_end__week
+ , subq_4.window_end__month
+ , subq_4.window_end__quarter
+ , subq_4.window_end__year
+ , subq_4.window_end__extract_year
+ , subq_4.window_end__extract_quarter
+ , subq_4.window_end__extract_month
+ , subq_4.window_end__extract_day
+ , subq_4.window_end__extract_dow
+ , subq_4.window_end__extract_doy
+ , subq_4.lux_listing__window_start__day
+ , subq_4.lux_listing__window_start__week
+ , subq_4.lux_listing__window_start__month
+ , subq_4.lux_listing__window_start__quarter
+ , subq_4.lux_listing__window_start__year
+ , subq_4.lux_listing__window_start__extract_year
+ , subq_4.lux_listing__window_start__extract_quarter
+ , subq_4.lux_listing__window_start__extract_month
+ , subq_4.lux_listing__window_start__extract_day
+ , subq_4.lux_listing__window_start__extract_dow
+ , subq_4.lux_listing__window_start__extract_doy
+ , subq_4.lux_listing__window_end__day
+ , subq_4.lux_listing__window_end__week
+ , subq_4.lux_listing__window_end__month
+ , subq_4.lux_listing__window_end__quarter
+ , subq_4.lux_listing__window_end__year
+ , subq_4.lux_listing__window_end__extract_year
+ , subq_4.lux_listing__window_end__extract_quarter
+ , subq_4.lux_listing__window_end__extract_month
+ , subq_4.lux_listing__window_end__extract_day
+ , subq_4.lux_listing__window_end__extract_dow
+ , subq_4.lux_listing__window_end__extract_doy
+ , subq_4.lux_listing
+ , subq_4.is_confirmed_lux
+ , subq_4.lux_listing__is_confirmed_lux
+ FROM (
+ -- Read Elements From Semantic Model 'lux_listings'
+ SELECT
+ lux_listings_src_10021.valid_from AS window_start__day
+ , DATE_TRUNC('week', lux_listings_src_10021.valid_from) AS window_start__week
+ , DATE_TRUNC('month', lux_listings_src_10021.valid_from) AS window_start__month
+ , DATE_TRUNC('quarter', lux_listings_src_10021.valid_from) AS window_start__quarter
+ , DATE_TRUNC('year', lux_listings_src_10021.valid_from) AS window_start__year
+ , EXTRACT(year FROM lux_listings_src_10021.valid_from) AS window_start__extract_year
+ , EXTRACT(quarter FROM lux_listings_src_10021.valid_from) AS window_start__extract_quarter
+ , EXTRACT(month FROM lux_listings_src_10021.valid_from) AS window_start__extract_month
+ , EXTRACT(day FROM lux_listings_src_10021.valid_from) AS window_start__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10021.valid_from) AS window_start__extract_dow
+ , EXTRACT(doy FROM lux_listings_src_10021.valid_from) AS window_start__extract_doy
+ , lux_listings_src_10021.valid_to AS window_end__day
+ , DATE_TRUNC('week', lux_listings_src_10021.valid_to) AS window_end__week
+ , DATE_TRUNC('month', lux_listings_src_10021.valid_to) AS window_end__month
+ , DATE_TRUNC('quarter', lux_listings_src_10021.valid_to) AS window_end__quarter
+ , DATE_TRUNC('year', lux_listings_src_10021.valid_to) AS window_end__year
+ , EXTRACT(year FROM lux_listings_src_10021.valid_to) AS window_end__extract_year
+ , EXTRACT(quarter FROM lux_listings_src_10021.valid_to) AS window_end__extract_quarter
+ , EXTRACT(month FROM lux_listings_src_10021.valid_to) AS window_end__extract_month
+ , EXTRACT(day FROM lux_listings_src_10021.valid_to) AS window_end__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10021.valid_to) AS window_end__extract_dow
+ , EXTRACT(doy FROM lux_listings_src_10021.valid_to) AS window_end__extract_doy
+ , lux_listings_src_10021.is_confirmed_lux
+ , lux_listings_src_10021.valid_from AS lux_listing__window_start__day
+ , DATE_TRUNC('week', lux_listings_src_10021.valid_from) AS lux_listing__window_start__week
+ , DATE_TRUNC('month', lux_listings_src_10021.valid_from) AS lux_listing__window_start__month
+ , DATE_TRUNC('quarter', lux_listings_src_10021.valid_from) AS lux_listing__window_start__quarter
+ , DATE_TRUNC('year', lux_listings_src_10021.valid_from) AS lux_listing__window_start__year
+ , EXTRACT(year FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_year
+ , EXTRACT(quarter FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_quarter
+ , EXTRACT(month FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_month
+ , EXTRACT(day FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_dow
+ , EXTRACT(doy FROM lux_listings_src_10021.valid_from) AS lux_listing__window_start__extract_doy
+ , lux_listings_src_10021.valid_to AS lux_listing__window_end__day
+ , DATE_TRUNC('week', lux_listings_src_10021.valid_to) AS lux_listing__window_end__week
+ , DATE_TRUNC('month', lux_listings_src_10021.valid_to) AS lux_listing__window_end__month
+ , DATE_TRUNC('quarter', lux_listings_src_10021.valid_to) AS lux_listing__window_end__quarter
+ , DATE_TRUNC('year', lux_listings_src_10021.valid_to) AS lux_listing__window_end__year
+ , EXTRACT(year FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_year
+ , EXTRACT(quarter FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_quarter
+ , EXTRACT(month FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_month
+ , EXTRACT(day FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_dow
+ , EXTRACT(doy FROM lux_listings_src_10021.valid_to) AS lux_listing__window_end__extract_doy
+ , lux_listings_src_10021.is_confirmed_lux AS lux_listing__is_confirmed_lux
+ , lux_listings_src_10021.lux_listing_id AS lux_listing
+ FROM ***************************.dim_lux_listings lux_listings_src_10021
+ ) subq_4
+ ) subq_5
+ ON
+ subq_3.lux_listing = subq_5.lux_listing
+ ) subq_6
+ ) subq_7
+ ON
+ (
+ subq_2.listing = subq_7.listing
+ ) AND (
+ (
+ subq_2.metric_time__day >= subq_7.lux_listing__window_start__day
+ ) AND (
+ (
+ subq_2.metric_time__day < subq_7.lux_listing__window_end__day
+ ) OR (
+ subq_7.lux_listing__window_end__day IS NULL
+ )
+ )
+ )
+ ) subq_8
+ ) subq_9
+ GROUP BY
+ subq_9.metric_time__day
+ , subq_9.listing__lux_listing__is_confirmed_lux
+) subq_10
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql
new file mode 100644
index 0000000000..16470814e6
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multi_hop_to_scd_dimension__plan0_optimized.sql
@@ -0,0 +1,55 @@
+-- Join Standard Outputs
+-- Pass Only Elements:
+-- ['bookings', 'listing__lux_listing__is_confirmed_lux', 'metric_time__day']
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ subq_13.metric_time__day AS metric_time__day
+ , subq_18.lux_listing__is_confirmed_lux AS listing__lux_listing__is_confirmed_lux
+ , SUM(subq_13.bookings) AS bookings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day', 'listing']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , listing_id AS listing
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10017
+) subq_13
+LEFT OUTER JOIN (
+ -- Join Standard Outputs
+ -- Pass Only Elements:
+ -- ['lux_listing__is_confirmed_lux',
+ -- 'lux_listing__window_start__day',
+ -- 'lux_listing__window_end__day',
+ -- 'listing']
+ SELECT
+ lux_listings_src_10021.valid_from AS lux_listing__window_start__day
+ , lux_listings_src_10021.valid_to AS lux_listing__window_end__day
+ , lux_listing_mapping_src_10020.listing_id AS listing
+ , lux_listings_src_10021.is_confirmed_lux AS lux_listing__is_confirmed_lux
+ FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_10020
+ LEFT OUTER JOIN
+ ***************************.dim_lux_listings lux_listings_src_10021
+ ON
+ lux_listing_mapping_src_10020.lux_listing_id = lux_listings_src_10021.lux_listing_id
+) subq_18
+ON
+ (
+ subq_13.listing = subq_18.listing
+ ) AND (
+ (
+ subq_13.metric_time__day >= subq_18.lux_listing__window_start__day
+ ) AND (
+ (
+ subq_13.metric_time__day < subq_18.lux_listing__window_end__day
+ ) OR (
+ subq_18.lux_listing__window_end__day IS NULL
+ )
+ )
+ )
+GROUP BY
+ subq_13.metric_time__day
+ , subq_18.lux_listing__is_confirmed_lux
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql
new file mode 100644
index 0000000000..499b9f8c12
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0.sql
@@ -0,0 +1,366 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_10.account_id__customer_id__customer_name
+ , subq_10.txn_count
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_9.account_id__customer_id__customer_name
+ , SUM(subq_9.txn_count) AS txn_count
+ FROM (
+ -- Pass Only Elements:
+ -- ['txn_count', 'account_id__customer_id__customer_name']
+ SELECT
+ subq_8.account_id__customer_id__customer_name
+ , subq_8.txn_count
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_2.ds_partitioned__day AS ds_partitioned__day
+ , subq_7.ds_partitioned__day AS account_id__ds_partitioned__day
+ , subq_2.account_id AS account_id
+ , subq_7.customer_id__customer_name AS account_id__customer_id__customer_name
+ , subq_2.txn_count AS txn_count
+ FROM (
+ -- Pass Only Elements:
+ -- ['txn_count', 'ds_partitioned__day', 'account_id']
+ SELECT
+ subq_1.ds_partitioned__day
+ , subq_1.account_id
+ , subq_1.txn_count
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ 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.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.account_id__ds_partitioned__day
+ , subq_0.account_id__ds_partitioned__week
+ , subq_0.account_id__ds_partitioned__month
+ , subq_0.account_id__ds_partitioned__quarter
+ , subq_0.account_id__ds_partitioned__year
+ , subq_0.account_id__ds_partitioned__extract_year
+ , subq_0.account_id__ds_partitioned__extract_quarter
+ , subq_0.account_id__ds_partitioned__extract_month
+ , subq_0.account_id__ds_partitioned__extract_day
+ , subq_0.account_id__ds_partitioned__extract_dow
+ , subq_0.account_id__ds_partitioned__extract_doy
+ , subq_0.account_id__ds__day
+ , subq_0.account_id__ds__week
+ , subq_0.account_id__ds__month
+ , subq_0.account_id__ds__quarter
+ , subq_0.account_id__ds__year
+ , subq_0.account_id__ds__extract_year
+ , subq_0.account_id__ds__extract_quarter
+ , subq_0.account_id__ds__extract_month
+ , subq_0.account_id__ds__extract_day
+ , subq_0.account_id__ds__extract_dow
+ , subq_0.account_id__ds__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.account_id
+ , subq_0.account_month
+ , subq_0.account_id__account_month
+ , subq_0.txn_count
+ FROM (
+ -- Read Elements From Semantic Model 'account_month_txns'
+ SELECT
+ account_month_txns_src_10012.txn_count
+ , DATE_TRUNC('day', account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM account_month_txns_src_10012.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', account_month_txns_src_10012.ds) AS ds__day
+ , DATE_TRUNC('week', account_month_txns_src_10012.ds) AS ds__week
+ , DATE_TRUNC('month', account_month_txns_src_10012.ds) AS ds__month
+ , DATE_TRUNC('quarter', account_month_txns_src_10012.ds) AS ds__quarter
+ , DATE_TRUNC('year', account_month_txns_src_10012.ds) AS ds__year
+ , EXTRACT(year FROM account_month_txns_src_10012.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM account_month_txns_src_10012.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM account_month_txns_src_10012.ds) AS ds__extract_month
+ , EXTRACT(day FROM account_month_txns_src_10012.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10012.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM account_month_txns_src_10012.ds) AS ds__extract_doy
+ , account_month_txns_src_10012.account_month
+ , DATE_TRUNC('day', account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__day
+ , DATE_TRUNC('week', account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__week
+ , DATE_TRUNC('month', account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__month
+ , DATE_TRUNC('quarter', account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__quarter
+ , DATE_TRUNC('year', account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__year
+ , EXTRACT(year FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_month
+ , EXTRACT(day FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM account_month_txns_src_10012.ds_partitioned) AS account_id__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', account_month_txns_src_10012.ds) AS account_id__ds__day
+ , DATE_TRUNC('week', account_month_txns_src_10012.ds) AS account_id__ds__week
+ , DATE_TRUNC('month', account_month_txns_src_10012.ds) AS account_id__ds__month
+ , DATE_TRUNC('quarter', account_month_txns_src_10012.ds) AS account_id__ds__quarter
+ , DATE_TRUNC('year', account_month_txns_src_10012.ds) AS account_id__ds__year
+ , EXTRACT(year FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_year
+ , EXTRACT(quarter FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_quarter
+ , EXTRACT(month FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_month
+ , EXTRACT(day FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_dow
+ , EXTRACT(doy FROM account_month_txns_src_10012.ds) AS account_id__ds__extract_doy
+ , account_month_txns_src_10012.account_month AS account_id__account_month
+ , account_month_txns_src_10012.account_id
+ FROM ***************************.account_month_txns account_month_txns_src_10012
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['customer_id__customer_name', 'ds_partitioned__day', 'account_id']
+ SELECT
+ subq_6.ds_partitioned__day
+ , subq_6.account_id
+ , subq_6.customer_id__customer_name
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_3.ds_partitioned__day AS ds_partitioned__day
+ , subq_3.ds_partitioned__week AS ds_partitioned__week
+ , subq_3.ds_partitioned__month AS ds_partitioned__month
+ , subq_3.ds_partitioned__quarter AS ds_partitioned__quarter
+ , subq_3.ds_partitioned__year AS ds_partitioned__year
+ , subq_3.ds_partitioned__extract_year AS ds_partitioned__extract_year
+ , subq_3.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter
+ , subq_3.ds_partitioned__extract_month AS ds_partitioned__extract_month
+ , subq_3.ds_partitioned__extract_day AS ds_partitioned__extract_day
+ , subq_3.ds_partitioned__extract_dow AS ds_partitioned__extract_dow
+ , subq_3.ds_partitioned__extract_doy AS ds_partitioned__extract_doy
+ , subq_3.account_id__ds_partitioned__day AS account_id__ds_partitioned__day
+ , subq_3.account_id__ds_partitioned__week AS account_id__ds_partitioned__week
+ , subq_3.account_id__ds_partitioned__month AS account_id__ds_partitioned__month
+ , subq_3.account_id__ds_partitioned__quarter AS account_id__ds_partitioned__quarter
+ , subq_3.account_id__ds_partitioned__year AS account_id__ds_partitioned__year
+ , subq_3.account_id__ds_partitioned__extract_year AS account_id__ds_partitioned__extract_year
+ , subq_3.account_id__ds_partitioned__extract_quarter AS account_id__ds_partitioned__extract_quarter
+ , subq_3.account_id__ds_partitioned__extract_month AS account_id__ds_partitioned__extract_month
+ , subq_3.account_id__ds_partitioned__extract_day AS account_id__ds_partitioned__extract_day
+ , subq_3.account_id__ds_partitioned__extract_dow AS account_id__ds_partitioned__extract_dow
+ , subq_3.account_id__ds_partitioned__extract_doy AS account_id__ds_partitioned__extract_doy
+ , subq_3.bridge_account__ds_partitioned__day AS bridge_account__ds_partitioned__day
+ , subq_3.bridge_account__ds_partitioned__week AS bridge_account__ds_partitioned__week
+ , subq_3.bridge_account__ds_partitioned__month AS bridge_account__ds_partitioned__month
+ , subq_3.bridge_account__ds_partitioned__quarter AS bridge_account__ds_partitioned__quarter
+ , subq_3.bridge_account__ds_partitioned__year AS bridge_account__ds_partitioned__year
+ , subq_3.bridge_account__ds_partitioned__extract_year AS bridge_account__ds_partitioned__extract_year
+ , subq_3.bridge_account__ds_partitioned__extract_quarter AS bridge_account__ds_partitioned__extract_quarter
+ , subq_3.bridge_account__ds_partitioned__extract_month AS bridge_account__ds_partitioned__extract_month
+ , subq_3.bridge_account__ds_partitioned__extract_day AS bridge_account__ds_partitioned__extract_day
+ , subq_3.bridge_account__ds_partitioned__extract_dow AS bridge_account__ds_partitioned__extract_dow
+ , subq_3.bridge_account__ds_partitioned__extract_doy AS bridge_account__ds_partitioned__extract_doy
+ , subq_5.ds_partitioned__day AS customer_id__ds_partitioned__day
+ , subq_5.ds_partitioned__week AS customer_id__ds_partitioned__week
+ , subq_5.ds_partitioned__month AS customer_id__ds_partitioned__month
+ , subq_5.ds_partitioned__quarter AS customer_id__ds_partitioned__quarter
+ , subq_5.ds_partitioned__year AS customer_id__ds_partitioned__year
+ , subq_5.ds_partitioned__extract_year AS customer_id__ds_partitioned__extract_year
+ , subq_5.ds_partitioned__extract_quarter AS customer_id__ds_partitioned__extract_quarter
+ , subq_5.ds_partitioned__extract_month AS customer_id__ds_partitioned__extract_month
+ , subq_5.ds_partitioned__extract_day AS customer_id__ds_partitioned__extract_day
+ , subq_5.ds_partitioned__extract_dow AS customer_id__ds_partitioned__extract_dow
+ , subq_5.ds_partitioned__extract_doy AS customer_id__ds_partitioned__extract_doy
+ , subq_3.account_id AS account_id
+ , subq_3.customer_id AS customer_id
+ , subq_3.account_id__customer_id AS account_id__customer_id
+ , subq_3.bridge_account__account_id AS bridge_account__account_id
+ , subq_3.bridge_account__customer_id AS bridge_account__customer_id
+ , subq_3.extra_dim AS extra_dim
+ , subq_3.account_id__extra_dim AS account_id__extra_dim
+ , subq_3.bridge_account__extra_dim AS bridge_account__extra_dim
+ , subq_5.customer_name AS customer_id__customer_name
+ , subq_5.customer_atomic_weight AS customer_id__customer_atomic_weight
+ FROM (
+ -- Read Elements From Semantic Model 'bridge_table'
+ SELECT
+ bridge_table_src_10013.extra_dim
+ , DATE_TRUNC('day', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bridge_table_src_10013.ds_partitioned) AS ds_partitioned__extract_doy
+ , bridge_table_src_10013.extra_dim AS account_id__extra_dim
+ , DATE_TRUNC('day', bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__day
+ , DATE_TRUNC('week', bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__week
+ , DATE_TRUNC('month', bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__month
+ , DATE_TRUNC('quarter', bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__quarter
+ , DATE_TRUNC('year', bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__year
+ , EXTRACT(year FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_month
+ , EXTRACT(day FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bridge_table_src_10013.ds_partitioned) AS account_id__ds_partitioned__extract_doy
+ , bridge_table_src_10013.extra_dim AS bridge_account__extra_dim
+ , DATE_TRUNC('day', bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__day
+ , DATE_TRUNC('week', bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__week
+ , DATE_TRUNC('month', bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__month
+ , DATE_TRUNC('quarter', bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__quarter
+ , DATE_TRUNC('year', bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__year
+ , EXTRACT(year FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_month
+ , EXTRACT(day FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bridge_table_src_10013.ds_partitioned) AS bridge_account__ds_partitioned__extract_doy
+ , bridge_table_src_10013.account_id
+ , bridge_table_src_10013.customer_id
+ , bridge_table_src_10013.customer_id AS account_id__customer_id
+ , bridge_table_src_10013.account_id AS bridge_account__account_id
+ , bridge_table_src_10013.customer_id AS bridge_account__customer_id
+ FROM ***************************.bridge_table bridge_table_src_10013
+ ) subq_3
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['customer_name',
+ -- 'customer_atomic_weight',
+ -- 'customer_id__customer_name',
+ -- 'customer_id__customer_atomic_weight',
+ -- 'ds_partitioned__day',
+ -- 'ds_partitioned__week',
+ -- 'ds_partitioned__month',
+ -- 'ds_partitioned__quarter',
+ -- 'ds_partitioned__year',
+ -- 'ds_partitioned__extract_year',
+ -- 'ds_partitioned__extract_quarter',
+ -- 'ds_partitioned__extract_month',
+ -- 'ds_partitioned__extract_day',
+ -- 'ds_partitioned__extract_dow',
+ -- 'ds_partitioned__extract_doy',
+ -- 'customer_id__ds_partitioned__day',
+ -- 'customer_id__ds_partitioned__week',
+ -- 'customer_id__ds_partitioned__month',
+ -- 'customer_id__ds_partitioned__quarter',
+ -- 'customer_id__ds_partitioned__year',
+ -- 'customer_id__ds_partitioned__extract_year',
+ -- 'customer_id__ds_partitioned__extract_quarter',
+ -- 'customer_id__ds_partitioned__extract_month',
+ -- 'customer_id__ds_partitioned__extract_day',
+ -- 'customer_id__ds_partitioned__extract_dow',
+ -- 'customer_id__ds_partitioned__extract_doy',
+ -- 'customer_id']
+ SELECT
+ subq_4.ds_partitioned__day
+ , subq_4.ds_partitioned__week
+ , subq_4.ds_partitioned__month
+ , subq_4.ds_partitioned__quarter
+ , subq_4.ds_partitioned__year
+ , subq_4.ds_partitioned__extract_year
+ , subq_4.ds_partitioned__extract_quarter
+ , subq_4.ds_partitioned__extract_month
+ , subq_4.ds_partitioned__extract_day
+ , subq_4.ds_partitioned__extract_dow
+ , subq_4.ds_partitioned__extract_doy
+ , subq_4.customer_id__ds_partitioned__day
+ , subq_4.customer_id__ds_partitioned__week
+ , subq_4.customer_id__ds_partitioned__month
+ , subq_4.customer_id__ds_partitioned__quarter
+ , subq_4.customer_id__ds_partitioned__year
+ , subq_4.customer_id__ds_partitioned__extract_year
+ , subq_4.customer_id__ds_partitioned__extract_quarter
+ , subq_4.customer_id__ds_partitioned__extract_month
+ , subq_4.customer_id__ds_partitioned__extract_day
+ , subq_4.customer_id__ds_partitioned__extract_dow
+ , subq_4.customer_id__ds_partitioned__extract_doy
+ , subq_4.customer_id
+ , subq_4.customer_name
+ , subq_4.customer_atomic_weight
+ , subq_4.customer_id__customer_name
+ , subq_4.customer_id__customer_atomic_weight
+ FROM (
+ -- Read Elements From Semantic Model 'customer_table'
+ SELECT
+ customer_table_src_10015.customer_name
+ , customer_table_src_10015.customer_atomic_weight
+ , DATE_TRUNC('day', customer_table_src_10015.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', customer_table_src_10015.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', customer_table_src_10015.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', customer_table_src_10015.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', customer_table_src_10015.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM customer_table_src_10015.ds_partitioned) AS ds_partitioned__extract_doy
+ , customer_table_src_10015.customer_name AS customer_id__customer_name
+ , customer_table_src_10015.customer_atomic_weight AS customer_id__customer_atomic_weight
+ , DATE_TRUNC('day', customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__day
+ , DATE_TRUNC('week', customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__week
+ , DATE_TRUNC('month', customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__month
+ , DATE_TRUNC('quarter', customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__quarter
+ , DATE_TRUNC('year', customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__year
+ , EXTRACT(year FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_month
+ , EXTRACT(day FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM customer_table_src_10015.ds_partitioned) AS customer_id__ds_partitioned__extract_doy
+ , customer_table_src_10015.customer_id
+ FROM ***************************.customer_table customer_table_src_10015
+ ) subq_4
+ ) subq_5
+ ON
+ (
+ subq_3.customer_id = subq_5.customer_id
+ ) AND (
+ subq_3.ds_partitioned__day = subq_5.ds_partitioned__day
+ )
+ ) subq_6
+ ) subq_7
+ ON
+ (
+ subq_2.account_id = subq_7.account_id
+ ) AND (
+ subq_2.ds_partitioned__day = subq_7.ds_partitioned__day
+ )
+ ) subq_8
+ ) subq_9
+ GROUP BY
+ subq_9.account_id__customer_id__customer_name
+) subq_10
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql
new file mode 100644
index 0000000000..65d688b745
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multihop_node__plan0_optimized.sql
@@ -0,0 +1,35 @@
+-- Join Standard Outputs
+-- Pass Only Elements:
+-- ['txn_count', 'account_id__customer_id__customer_name']
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ subq_18.customer_id__customer_name AS account_id__customer_id__customer_name
+ , SUM(account_month_txns_src_10012.txn_count) AS txn_count
+FROM ***************************.account_month_txns account_month_txns_src_10012
+LEFT OUTER JOIN (
+ -- Join Standard Outputs
+ -- Pass Only Elements:
+ -- ['customer_id__customer_name', 'ds_partitioned__day', 'account_id']
+ SELECT
+ DATE_TRUNC('day', bridge_table_src_10013.ds_partitioned) AS ds_partitioned__day
+ , bridge_table_src_10013.account_id AS account_id
+ , customer_table_src_10015.customer_name AS customer_id__customer_name
+ FROM ***************************.bridge_table bridge_table_src_10013
+ LEFT OUTER JOIN
+ ***************************.customer_table customer_table_src_10015
+ ON
+ (
+ bridge_table_src_10013.customer_id = customer_table_src_10015.customer_id
+ ) AND (
+ DATE_TRUNC('day', bridge_table_src_10013.ds_partitioned) = DATE_TRUNC('day', customer_table_src_10015.ds_partitioned)
+ )
+) subq_18
+ON
+ (
+ account_month_txns_src_10012.account_id = subq_18.account_id
+ ) AND (
+ DATE_TRUNC('day', account_month_txns_src_10012.ds_partitioned) = subq_18.ds_partitioned__day
+ )
+GROUP BY
+ subq_18.customer_id__customer_name
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql
new file mode 100644
index 0000000000..657579fe50
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0.sql
@@ -0,0 +1,538 @@
+-- Combine Aggregated Outputs
+SELECT
+ MAX(subq_5.bookings) AS bookings
+ , MAX(subq_11.listings) AS listings
+FROM (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_4.bookings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_3.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings']
+ SELECT
+ subq_2.bookings
+ FROM (
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
+ SELECT
+ subq_1.ds__day
+ , subq_1.ds__week
+ , subq_1.ds__month
+ , subq_1.ds__quarter
+ , subq_1.ds__year
+ , subq_1.ds__extract_year
+ , subq_1.ds__extract_quarter
+ , subq_1.ds__extract_month
+ , subq_1.ds__extract_day
+ , subq_1.ds__extract_dow
+ , subq_1.ds__extract_doy
+ , subq_1.ds_partitioned__day
+ , subq_1.ds_partitioned__week
+ , subq_1.ds_partitioned__month
+ , subq_1.ds_partitioned__quarter
+ , subq_1.ds_partitioned__year
+ , subq_1.ds_partitioned__extract_year
+ , subq_1.ds_partitioned__extract_quarter
+ , subq_1.ds_partitioned__extract_month
+ , subq_1.ds_partitioned__extract_day
+ , subq_1.ds_partitioned__extract_dow
+ , subq_1.ds_partitioned__extract_doy
+ , subq_1.paid_at__day
+ , subq_1.paid_at__week
+ , subq_1.paid_at__month
+ , subq_1.paid_at__quarter
+ , subq_1.paid_at__year
+ , subq_1.paid_at__extract_year
+ , subq_1.paid_at__extract_quarter
+ , subq_1.paid_at__extract_month
+ , subq_1.paid_at__extract_day
+ , subq_1.paid_at__extract_dow
+ , subq_1.paid_at__extract_doy
+ , subq_1.booking__ds__day
+ , subq_1.booking__ds__week
+ , subq_1.booking__ds__month
+ , subq_1.booking__ds__quarter
+ , subq_1.booking__ds__year
+ , subq_1.booking__ds__extract_year
+ , subq_1.booking__ds__extract_quarter
+ , subq_1.booking__ds__extract_month
+ , subq_1.booking__ds__extract_day
+ , subq_1.booking__ds__extract_dow
+ , subq_1.booking__ds__extract_doy
+ , subq_1.booking__ds_partitioned__day
+ , subq_1.booking__ds_partitioned__week
+ , subq_1.booking__ds_partitioned__month
+ , subq_1.booking__ds_partitioned__quarter
+ , subq_1.booking__ds_partitioned__year
+ , subq_1.booking__ds_partitioned__extract_year
+ , subq_1.booking__ds_partitioned__extract_quarter
+ , subq_1.booking__ds_partitioned__extract_month
+ , subq_1.booking__ds_partitioned__extract_day
+ , subq_1.booking__ds_partitioned__extract_dow
+ , subq_1.booking__ds_partitioned__extract_doy
+ , subq_1.booking__paid_at__day
+ , subq_1.booking__paid_at__week
+ , subq_1.booking__paid_at__month
+ , subq_1.booking__paid_at__quarter
+ , subq_1.booking__paid_at__year
+ , subq_1.booking__paid_at__extract_year
+ , subq_1.booking__paid_at__extract_quarter
+ , subq_1.booking__paid_at__extract_month
+ , subq_1.booking__paid_at__extract_day
+ , subq_1.booking__paid_at__extract_dow
+ , subq_1.booking__paid_at__extract_doy
+ , subq_1.metric_time__day
+ , subq_1.metric_time__week
+ , subq_1.metric_time__month
+ , subq_1.metric_time__quarter
+ , subq_1.metric_time__year
+ , subq_1.metric_time__extract_year
+ , subq_1.metric_time__extract_quarter
+ , subq_1.metric_time__extract_month
+ , subq_1.metric_time__extract_day
+ , subq_1.metric_time__extract_dow
+ , subq_1.metric_time__extract_doy
+ , subq_1.listing
+ , subq_1.guest
+ , subq_1.host
+ , subq_1.booking__listing
+ , subq_1.booking__guest
+ , subq_1.booking__host
+ , subq_1.is_instant
+ , subq_1.booking__is_instant
+ , subq_1.bookings
+ , subq_1.instant_bookings
+ , subq_1.booking_value
+ , subq_1.max_booking_value
+ , subq_1.min_booking_value
+ , subq_1.bookers
+ , subq_1.average_booking_value
+ , subq_1.referred_bookings
+ , subq_1.median_booking_value
+ , subq_1.booking_value_p99
+ , subq_1.discrete_booking_value_p99
+ , subq_1.approximate_continuous_booking_value_p99
+ , subq_1.approximate_discrete_booking_value_p99
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ WHERE subq_1.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01'
+ ) subq_2
+ ) subq_3
+ ) subq_4
+) subq_5
+CROSS JOIN (
+ -- Compute Metrics via Expressions
+ SELECT
+ subq_10.listings
+ FROM (
+ -- Aggregate Measures
+ SELECT
+ SUM(subq_9.listings) AS listings
+ FROM (
+ -- Pass Only Elements:
+ -- ['listings']
+ SELECT
+ subq_8.listings
+ FROM (
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
+ SELECT
+ subq_7.ds__day
+ , subq_7.ds__week
+ , subq_7.ds__month
+ , subq_7.ds__quarter
+ , subq_7.ds__year
+ , subq_7.ds__extract_year
+ , subq_7.ds__extract_quarter
+ , subq_7.ds__extract_month
+ , subq_7.ds__extract_day
+ , subq_7.ds__extract_dow
+ , subq_7.ds__extract_doy
+ , subq_7.created_at__day
+ , subq_7.created_at__week
+ , subq_7.created_at__month
+ , subq_7.created_at__quarter
+ , subq_7.created_at__year
+ , subq_7.created_at__extract_year
+ , subq_7.created_at__extract_quarter
+ , subq_7.created_at__extract_month
+ , subq_7.created_at__extract_day
+ , subq_7.created_at__extract_dow
+ , subq_7.created_at__extract_doy
+ , subq_7.listing__ds__day
+ , subq_7.listing__ds__week
+ , subq_7.listing__ds__month
+ , subq_7.listing__ds__quarter
+ , subq_7.listing__ds__year
+ , subq_7.listing__ds__extract_year
+ , subq_7.listing__ds__extract_quarter
+ , subq_7.listing__ds__extract_month
+ , subq_7.listing__ds__extract_day
+ , subq_7.listing__ds__extract_dow
+ , subq_7.listing__ds__extract_doy
+ , subq_7.listing__created_at__day
+ , subq_7.listing__created_at__week
+ , subq_7.listing__created_at__month
+ , subq_7.listing__created_at__quarter
+ , subq_7.listing__created_at__year
+ , subq_7.listing__created_at__extract_year
+ , subq_7.listing__created_at__extract_quarter
+ , subq_7.listing__created_at__extract_month
+ , subq_7.listing__created_at__extract_day
+ , subq_7.listing__created_at__extract_dow
+ , subq_7.listing__created_at__extract_doy
+ , subq_7.metric_time__day
+ , subq_7.metric_time__week
+ , subq_7.metric_time__month
+ , subq_7.metric_time__quarter
+ , subq_7.metric_time__year
+ , subq_7.metric_time__extract_year
+ , subq_7.metric_time__extract_quarter
+ , subq_7.metric_time__extract_month
+ , subq_7.metric_time__extract_day
+ , subq_7.metric_time__extract_dow
+ , subq_7.metric_time__extract_doy
+ , subq_7.listing
+ , subq_7.user
+ , subq_7.listing__user
+ , subq_7.country_latest
+ , subq_7.is_lux_latest
+ , subq_7.capacity_latest
+ , subq_7.listing__country_latest
+ , subq_7.listing__is_lux_latest
+ , subq_7.listing__capacity_latest
+ , subq_7.listings
+ , subq_7.largest_listing
+ , subq_7.smallest_listing
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_6.ds__day
+ , subq_6.ds__week
+ , subq_6.ds__month
+ , subq_6.ds__quarter
+ , subq_6.ds__year
+ , subq_6.ds__extract_year
+ , subq_6.ds__extract_quarter
+ , subq_6.ds__extract_month
+ , subq_6.ds__extract_day
+ , subq_6.ds__extract_dow
+ , subq_6.ds__extract_doy
+ , subq_6.created_at__day
+ , subq_6.created_at__week
+ , subq_6.created_at__month
+ , subq_6.created_at__quarter
+ , subq_6.created_at__year
+ , subq_6.created_at__extract_year
+ , subq_6.created_at__extract_quarter
+ , subq_6.created_at__extract_month
+ , subq_6.created_at__extract_day
+ , subq_6.created_at__extract_dow
+ , subq_6.created_at__extract_doy
+ , subq_6.listing__ds__day
+ , subq_6.listing__ds__week
+ , subq_6.listing__ds__month
+ , subq_6.listing__ds__quarter
+ , subq_6.listing__ds__year
+ , subq_6.listing__ds__extract_year
+ , subq_6.listing__ds__extract_quarter
+ , subq_6.listing__ds__extract_month
+ , subq_6.listing__ds__extract_day
+ , subq_6.listing__ds__extract_dow
+ , subq_6.listing__ds__extract_doy
+ , subq_6.listing__created_at__day
+ , subq_6.listing__created_at__week
+ , subq_6.listing__created_at__month
+ , subq_6.listing__created_at__quarter
+ , subq_6.listing__created_at__year
+ , subq_6.listing__created_at__extract_year
+ , subq_6.listing__created_at__extract_quarter
+ , subq_6.listing__created_at__extract_month
+ , subq_6.listing__created_at__extract_day
+ , subq_6.listing__created_at__extract_dow
+ , subq_6.listing__created_at__extract_doy
+ , subq_6.ds__day AS metric_time__day
+ , subq_6.ds__week AS metric_time__week
+ , subq_6.ds__month AS metric_time__month
+ , subq_6.ds__quarter AS metric_time__quarter
+ , subq_6.ds__year AS metric_time__year
+ , subq_6.ds__extract_year AS metric_time__extract_year
+ , subq_6.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_6.ds__extract_month AS metric_time__extract_month
+ , subq_6.ds__extract_day AS metric_time__extract_day
+ , subq_6.ds__extract_dow AS metric_time__extract_dow
+ , subq_6.ds__extract_doy AS metric_time__extract_doy
+ , subq_6.listing
+ , subq_6.user
+ , subq_6.listing__user
+ , subq_6.country_latest
+ , subq_6.is_lux_latest
+ , subq_6.capacity_latest
+ , subq_6.listing__country_latest
+ , subq_6.listing__is_lux_latest
+ , subq_6.listing__capacity_latest
+ , subq_6.listings
+ , subq_6.largest_listing
+ , subq_6.smallest_listing
+ FROM (
+ -- Read Elements From Semantic Model 'listings_latest'
+ SELECT
+ 1 AS listings
+ , listings_latest_src_10005.capacity AS largest_listing
+ , listings_latest_src_10005.capacity AS smallest_listing
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS created_at__extract_doy
+ , listings_latest_src_10005.country AS country_latest
+ , listings_latest_src_10005.is_lux AS is_lux_latest
+ , listings_latest_src_10005.capacity AS capacity_latest
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__ds__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__ds__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__ds__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__ds__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__ds__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__ds__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__ds__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__ds__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__ds__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__ds__extract_doy
+ , DATE_TRUNC('day', listings_latest_src_10005.created_at) AS listing__created_at__day
+ , DATE_TRUNC('week', listings_latest_src_10005.created_at) AS listing__created_at__week
+ , DATE_TRUNC('month', listings_latest_src_10005.created_at) AS listing__created_at__month
+ , DATE_TRUNC('quarter', listings_latest_src_10005.created_at) AS listing__created_at__quarter
+ , DATE_TRUNC('year', listings_latest_src_10005.created_at) AS listing__created_at__year
+ , EXTRACT(year FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_year
+ , EXTRACT(quarter FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_quarter
+ , EXTRACT(month FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_month
+ , EXTRACT(day FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_dow
+ , EXTRACT(doy FROM listings_latest_src_10005.created_at) AS listing__created_at__extract_doy
+ , listings_latest_src_10005.country AS listing__country_latest
+ , listings_latest_src_10005.is_lux AS listing__is_lux_latest
+ , listings_latest_src_10005.capacity AS listing__capacity_latest
+ , listings_latest_src_10005.listing_id AS listing
+ , listings_latest_src_10005.user_id AS user
+ , listings_latest_src_10005.user_id AS listing__user
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ ) subq_6
+ ) subq_7
+ WHERE subq_7.metric_time__day BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01'
+ ) subq_8
+ ) subq_9
+ ) subq_10
+) subq_11
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql
new file mode 100644
index 0000000000..3c0ea8fcbb
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_multiple_metrics_no_dimensions__plan0_optimized.sql
@@ -0,0 +1,30 @@
+-- Combine Aggregated Outputs
+SELECT
+ MAX(subq_17.bookings) AS bookings
+ , MAX(subq_23.listings) AS listings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
+ -- Pass Only Elements:
+ -- ['bookings']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ SUM(1) AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ WHERE DATE_TRUNC('day', ds) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01'
+) subq_17
+CROSS JOIN (
+ -- Read Elements From Semantic Model 'listings_latest'
+ -- Metric Time Dimension 'ds'
+ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00]
+ -- Pass Only Elements:
+ -- ['listings']
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ SUM(1) AS listings
+ FROM ***************************.dim_listings_latest listings_latest_src_10005
+ WHERE DATE_TRUNC('day', created_at) BETWEEN timestamp '2020-01-01' AND timestamp '2020-01-01'
+) subq_23
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql
new file mode 100644
index 0000000000..cf515d8b83
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0.sql
@@ -0,0 +1,244 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_7.user__home_state
+ , subq_7.identity_verifications
+FROM (
+ -- Aggregate Measures
+ SELECT
+ subq_6.user__home_state
+ , SUM(subq_6.identity_verifications) AS identity_verifications
+ FROM (
+ -- Pass Only Elements:
+ -- ['identity_verifications', 'user__home_state']
+ SELECT
+ subq_5.user__home_state
+ , subq_5.identity_verifications
+ FROM (
+ -- Join Standard Outputs
+ SELECT
+ subq_2.ds_partitioned__day AS ds_partitioned__day
+ , subq_4.ds_partitioned__day AS user__ds_partitioned__day
+ , subq_2.user AS user
+ , subq_4.home_state AS user__home_state
+ , subq_2.identity_verifications AS identity_verifications
+ FROM (
+ -- Pass Only Elements:
+ -- ['identity_verifications', 'ds_partitioned__day', 'user']
+ SELECT
+ subq_1.ds_partitioned__day
+ , subq_1.user
+ , subq_1.identity_verifications
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.verification__ds__day
+ , subq_0.verification__ds__week
+ , subq_0.verification__ds__month
+ , subq_0.verification__ds__quarter
+ , subq_0.verification__ds__year
+ , subq_0.verification__ds__extract_year
+ , subq_0.verification__ds__extract_quarter
+ , subq_0.verification__ds__extract_month
+ , subq_0.verification__ds__extract_day
+ , subq_0.verification__ds__extract_dow
+ , subq_0.verification__ds__extract_doy
+ , subq_0.verification__ds_partitioned__day
+ , subq_0.verification__ds_partitioned__week
+ , subq_0.verification__ds_partitioned__month
+ , subq_0.verification__ds_partitioned__quarter
+ , subq_0.verification__ds_partitioned__year
+ , subq_0.verification__ds_partitioned__extract_year
+ , subq_0.verification__ds_partitioned__extract_quarter
+ , subq_0.verification__ds_partitioned__extract_month
+ , subq_0.verification__ds_partitioned__extract_day
+ , subq_0.verification__ds_partitioned__extract_dow
+ , subq_0.verification__ds_partitioned__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.verification
+ , subq_0.user
+ , subq_0.verification__user
+ , subq_0.verification_type
+ , subq_0.verification__verification_type
+ , subq_0.identity_verifications
+ FROM (
+ -- Read Elements From Semantic Model 'id_verifications'
+ SELECT
+ 1 AS identity_verifications
+ , DATE_TRUNC('day', id_verifications_src_10004.ds) AS ds__day
+ , DATE_TRUNC('week', id_verifications_src_10004.ds) AS ds__week
+ , DATE_TRUNC('month', id_verifications_src_10004.ds) AS ds__month
+ , DATE_TRUNC('quarter', id_verifications_src_10004.ds) AS ds__quarter
+ , DATE_TRUNC('year', id_verifications_src_10004.ds) AS ds__year
+ , EXTRACT(year FROM id_verifications_src_10004.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM id_verifications_src_10004.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM id_verifications_src_10004.ds) AS ds__extract_month
+ , EXTRACT(day FROM id_verifications_src_10004.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM id_verifications_src_10004.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', id_verifications_src_10004.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM id_verifications_src_10004.ds_partitioned) AS ds_partitioned__extract_doy
+ , id_verifications_src_10004.verification_type
+ , DATE_TRUNC('day', id_verifications_src_10004.ds) AS verification__ds__day
+ , DATE_TRUNC('week', id_verifications_src_10004.ds) AS verification__ds__week
+ , DATE_TRUNC('month', id_verifications_src_10004.ds) AS verification__ds__month
+ , DATE_TRUNC('quarter', id_verifications_src_10004.ds) AS verification__ds__quarter
+ , DATE_TRUNC('year', id_verifications_src_10004.ds) AS verification__ds__year
+ , EXTRACT(year FROM id_verifications_src_10004.ds) AS verification__ds__extract_year
+ , EXTRACT(quarter FROM id_verifications_src_10004.ds) AS verification__ds__extract_quarter
+ , EXTRACT(month FROM id_verifications_src_10004.ds) AS verification__ds__extract_month
+ , EXTRACT(day FROM id_verifications_src_10004.ds) AS verification__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds) AS verification__ds__extract_dow
+ , EXTRACT(doy FROM id_verifications_src_10004.ds) AS verification__ds__extract_doy
+ , DATE_TRUNC('day', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__day
+ , DATE_TRUNC('week', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__week
+ , DATE_TRUNC('month', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__month
+ , DATE_TRUNC('quarter', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__quarter
+ , DATE_TRUNC('year', id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__year
+ , EXTRACT(year FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_month
+ , EXTRACT(day FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM id_verifications_src_10004.ds_partitioned) AS verification__ds_partitioned__extract_doy
+ , id_verifications_src_10004.verification_type AS verification__verification_type
+ , id_verifications_src_10004.verification_id AS verification
+ , id_verifications_src_10004.user_id AS user
+ , id_verifications_src_10004.user_id AS verification__user
+ FROM ***************************.fct_id_verifications id_verifications_src_10004
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ LEFT OUTER JOIN (
+ -- Pass Only Elements:
+ -- ['home_state', 'ds_partitioned__day', 'user']
+ SELECT
+ subq_3.ds_partitioned__day
+ , subq_3.user
+ , subq_3.home_state
+ FROM (
+ -- Read Elements From Semantic Model 'users_ds_source'
+ SELECT
+ DATE_TRUNC('day', users_ds_source_src_10008.ds) AS ds__day
+ , DATE_TRUNC('week', users_ds_source_src_10008.ds) AS ds__week
+ , DATE_TRUNC('month', users_ds_source_src_10008.ds) AS ds__month
+ , DATE_TRUNC('quarter', users_ds_source_src_10008.ds) AS ds__quarter
+ , DATE_TRUNC('year', users_ds_source_src_10008.ds) AS ds__year
+ , EXTRACT(year FROM users_ds_source_src_10008.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM users_ds_source_src_10008.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM users_ds_source_src_10008.ds) AS ds__extract_month
+ , EXTRACT(day FROM users_ds_source_src_10008.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM users_ds_source_src_10008.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', users_ds_source_src_10008.created_at) AS created_at__day
+ , DATE_TRUNC('week', users_ds_source_src_10008.created_at) AS created_at__week
+ , DATE_TRUNC('month', users_ds_source_src_10008.created_at) AS created_at__month
+ , DATE_TRUNC('quarter', users_ds_source_src_10008.created_at) AS created_at__quarter
+ , DATE_TRUNC('year', users_ds_source_src_10008.created_at) AS created_at__year
+ , EXTRACT(year FROM users_ds_source_src_10008.created_at) AS created_at__extract_year
+ , EXTRACT(quarter FROM users_ds_source_src_10008.created_at) AS created_at__extract_quarter
+ , EXTRACT(month FROM users_ds_source_src_10008.created_at) AS created_at__extract_month
+ , EXTRACT(day FROM users_ds_source_src_10008.created_at) AS created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.created_at) AS created_at__extract_dow
+ , EXTRACT(doy FROM users_ds_source_src_10008.created_at) AS created_at__extract_doy
+ , DATE_TRUNC('day', users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM users_ds_source_src_10008.ds_partitioned) AS ds_partitioned__extract_doy
+ , users_ds_source_src_10008.home_state
+ , DATE_TRUNC('day', users_ds_source_src_10008.ds) AS user__ds__day
+ , DATE_TRUNC('week', users_ds_source_src_10008.ds) AS user__ds__week
+ , DATE_TRUNC('month', users_ds_source_src_10008.ds) AS user__ds__month
+ , DATE_TRUNC('quarter', users_ds_source_src_10008.ds) AS user__ds__quarter
+ , DATE_TRUNC('year', users_ds_source_src_10008.ds) AS user__ds__year
+ , EXTRACT(year FROM users_ds_source_src_10008.ds) AS user__ds__extract_year
+ , EXTRACT(quarter FROM users_ds_source_src_10008.ds) AS user__ds__extract_quarter
+ , EXTRACT(month FROM users_ds_source_src_10008.ds) AS user__ds__extract_month
+ , EXTRACT(day FROM users_ds_source_src_10008.ds) AS user__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.ds) AS user__ds__extract_dow
+ , EXTRACT(doy FROM users_ds_source_src_10008.ds) AS user__ds__extract_doy
+ , DATE_TRUNC('day', users_ds_source_src_10008.created_at) AS user__created_at__day
+ , DATE_TRUNC('week', users_ds_source_src_10008.created_at) AS user__created_at__week
+ , DATE_TRUNC('month', users_ds_source_src_10008.created_at) AS user__created_at__month
+ , DATE_TRUNC('quarter', users_ds_source_src_10008.created_at) AS user__created_at__quarter
+ , DATE_TRUNC('year', users_ds_source_src_10008.created_at) AS user__created_at__year
+ , EXTRACT(year FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_year
+ , EXTRACT(quarter FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_quarter
+ , EXTRACT(month FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_month
+ , EXTRACT(day FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_dow
+ , EXTRACT(doy FROM users_ds_source_src_10008.created_at) AS user__created_at__extract_doy
+ , DATE_TRUNC('day', users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__day
+ , DATE_TRUNC('week', users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__week
+ , DATE_TRUNC('month', users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__month
+ , DATE_TRUNC('quarter', users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__quarter
+ , DATE_TRUNC('year', users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__year
+ , EXTRACT(year FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_month
+ , EXTRACT(day FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM users_ds_source_src_10008.ds_partitioned) AS user__ds_partitioned__extract_doy
+ , users_ds_source_src_10008.home_state AS user__home_state
+ , users_ds_source_src_10008.user_id AS user
+ FROM ***************************.dim_users users_ds_source_src_10008
+ ) subq_3
+ ) subq_4
+ ON
+ (
+ subq_2.user = subq_4.user
+ ) AND (
+ subq_2.ds_partitioned__day = subq_4.ds_partitioned__day
+ )
+ ) subq_5
+ ) subq_6
+ GROUP BY
+ subq_6.user__home_state
+) subq_7
diff --git a/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql
new file mode 100644
index 0000000000..b52d743037
--- /dev/null
+++ b/metricflow/test/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_partitioned_join__plan0_optimized.sql
@@ -0,0 +1,29 @@
+-- Join Standard Outputs
+-- Pass Only Elements:
+-- ['identity_verifications', 'user__home_state']
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ users_ds_source_src_10008.home_state AS user__home_state
+ , SUM(subq_10.identity_verifications) AS identity_verifications
+FROM (
+ -- Read Elements From Semantic Model 'id_verifications'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['identity_verifications', 'ds_partitioned__day', 'user']
+ SELECT
+ DATE_TRUNC('day', ds_partitioned) AS ds_partitioned__day
+ , user_id AS user
+ , 1 AS identity_verifications
+ FROM ***************************.fct_id_verifications id_verifications_src_10004
+) subq_10
+LEFT OUTER JOIN
+ ***************************.dim_users users_ds_source_src_10008
+ON
+ (
+ subq_10.user = users_ds_source_src_10008.user_id
+ ) AND (
+ subq_10.ds_partitioned__day = DATE_TRUNC('day', users_ds_source_src_10008.ds_partitioned)
+ )
+GROUP BY
+ users_ds_source_src_10008.home_state
diff --git a/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_query__query0.sql b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_query__query0.sql
new file mode 100644
index 0000000000..a3bb3c8e79
--- /dev/null
+++ b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_query__query0.sql
@@ -0,0 +1,17 @@
+-- Aggregate Measures
+-- Compute Metrics via Expressions
+SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_1
+) subq_2
+GROUP BY
+ metric_time__day
diff --git a/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_write_to_table_query__query0.sql b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_write_to_table_query__query0.sql
new file mode 100644
index 0000000000..584414321a
--- /dev/null
+++ b/metricflow/test/snapshots/test_rendered_query.py/MetricFlowExplainResult/Trino/test_render_write_to_table_query__query0.sql
@@ -0,0 +1,19 @@
+CREATE TABLE ***************************.test_table AS (
+ -- Aggregate Measures
+ -- Compute Metrics via Expressions
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_1
+ ) subq_2
+ GROUP BY
+ metric_time__day
+)
diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan0.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan0.sql
new file mode 100644
index 0000000000..94a467a61a
--- /dev/null
+++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan0.sql
@@ -0,0 +1,4 @@
+-- test0
+SELECT
+ SUM(1) AS bookings
+FROM demo.fct_bookings a
diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan1.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan1.sql
new file mode 100644
index 0000000000..4f2811f3ab
--- /dev/null
+++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan1.sql
@@ -0,0 +1,6 @@
+-- test1
+SELECT
+ SUM(1) AS bookings
+ , b.country AS user__country
+ , c.country AS listing__country
+FROM demo.fct_bookings a
diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan2.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan2.sql
new file mode 100644
index 0000000000..9084cacd9c
--- /dev/null
+++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan2.sql
@@ -0,0 +1,10 @@
+-- test2
+SELECT
+ SUM(1) AS bookings
+ , b.country AS user__country
+ , c.country AS listing__country
+FROM demo.fct_bookings a
+LEFT OUTER JOIN
+ demo.dim_users b
+ON
+ a.user_id = b.user_id
diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan3.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan3.sql
new file mode 100644
index 0000000000..e283f191ed
--- /dev/null
+++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan3.sql
@@ -0,0 +1,14 @@
+-- test3
+SELECT
+ SUM(1) AS bookings
+ , b.country AS user__country
+ , c.country AS listing__country
+FROM demo.fct_bookings a
+LEFT OUTER JOIN
+ demo.dim_users b
+ON
+ a.user_id = b.user_id
+LEFT OUTER JOIN
+ demo.dim_listings c
+ON
+ a.user_id = c.user_id
diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan4.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan4.sql
new file mode 100644
index 0000000000..50c2a20f46
--- /dev/null
+++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan4.sql
@@ -0,0 +1,16 @@
+-- test4
+SELECT
+ SUM(1) AS bookings
+ , b.country AS user__country
+ , c.country AS listing__country
+FROM demo.fct_bookings a
+LEFT OUTER JOIN
+ demo.dim_users b
+ON
+ a.user_id = b.user_id
+LEFT OUTER JOIN
+ demo.dim_listings c
+ON
+ a.user_id = c.user_id
+GROUP BY
+ b.country
diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan5.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan5.sql
new file mode 100644
index 0000000000..98affe9d30
--- /dev/null
+++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_component_rendering__plan5.sql
@@ -0,0 +1,17 @@
+-- test5
+SELECT
+ SUM(1) AS bookings
+ , b.country AS user__country
+ , c.country AS listing__country
+FROM demo.fct_bookings a
+LEFT OUTER JOIN
+ demo.dim_users b
+ON
+ a.user_id = b.user_id
+LEFT OUTER JOIN
+ demo.dim_listings c
+ON
+ a.user_id = c.user_id
+GROUP BY
+ b.country
+ , c.country
diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_limit__plan0.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_limit__plan0.sql
new file mode 100644
index 0000000000..5720a09db8
--- /dev/null
+++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_limit__plan0.sql
@@ -0,0 +1,5 @@
+-- test0
+SELECT
+ a.bookings
+FROM demo.fct_bookings a
+LIMIT 1
diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_order_by__plan0.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_order_by__plan0.sql
new file mode 100644
index 0000000000..bef477c2b8
--- /dev/null
+++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_order_by__plan0.sql
@@ -0,0 +1,6 @@
+-- test0
+SELECT
+ a.booking_value
+ , a.bookings
+FROM demo.fct_bookings a
+ORDER BY a.booking_value, a.bookings DESC
diff --git a/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_where__plan0.sql b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_where__plan0.sql
new file mode 100644
index 0000000000..0f17ba24b2
--- /dev/null
+++ b/metricflow/test/snapshots/test_sql_plan_render.py/SqlQueryPlan/Trino/test_render_where__plan0.sql
@@ -0,0 +1,5 @@
+-- test0
+SELECT
+ a.booking_value
+FROM demo.fct_bookings a
+WHERE a.booking_value > 100
diff --git a/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql b/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql
new file mode 100644
index 0000000000..250642f628
--- /dev/null
+++ b/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0.sql
@@ -0,0 +1,228 @@
+-- Compute Metrics via Expressions
+SELECT
+ subq_6.metric_time__day
+ , subq_6.bookings AS bookings_join_to_time_spine
+FROM (
+ -- Join to Time Spine Dataset
+ SELECT
+ subq_4.metric_time__day AS metric_time__day
+ , subq_3.bookings AS bookings
+ FROM (
+ -- Date Spine
+ SELECT
+ subq_5.ds AS metric_time__day
+ FROM ***************************.mf_time_spine subq_5
+ ) subq_4
+ LEFT OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ subq_2.metric_time__day
+ , SUM(subq_2.bookings) AS bookings
+ FROM (
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ subq_1.metric_time__day
+ , subq_1.bookings
+ FROM (
+ -- Metric Time Dimension 'ds'
+ SELECT
+ subq_0.ds__day
+ , subq_0.ds__week
+ , subq_0.ds__month
+ , subq_0.ds__quarter
+ , subq_0.ds__year
+ , subq_0.ds__extract_year
+ , subq_0.ds__extract_quarter
+ , subq_0.ds__extract_month
+ , subq_0.ds__extract_day
+ , subq_0.ds__extract_dow
+ , subq_0.ds__extract_doy
+ , subq_0.ds_partitioned__day
+ , subq_0.ds_partitioned__week
+ , subq_0.ds_partitioned__month
+ , subq_0.ds_partitioned__quarter
+ , subq_0.ds_partitioned__year
+ , subq_0.ds_partitioned__extract_year
+ , subq_0.ds_partitioned__extract_quarter
+ , subq_0.ds_partitioned__extract_month
+ , subq_0.ds_partitioned__extract_day
+ , subq_0.ds_partitioned__extract_dow
+ , subq_0.ds_partitioned__extract_doy
+ , subq_0.paid_at__day
+ , subq_0.paid_at__week
+ , subq_0.paid_at__month
+ , subq_0.paid_at__quarter
+ , subq_0.paid_at__year
+ , subq_0.paid_at__extract_year
+ , subq_0.paid_at__extract_quarter
+ , subq_0.paid_at__extract_month
+ , subq_0.paid_at__extract_day
+ , subq_0.paid_at__extract_dow
+ , subq_0.paid_at__extract_doy
+ , subq_0.booking__ds__day
+ , subq_0.booking__ds__week
+ , subq_0.booking__ds__month
+ , subq_0.booking__ds__quarter
+ , subq_0.booking__ds__year
+ , subq_0.booking__ds__extract_year
+ , subq_0.booking__ds__extract_quarter
+ , subq_0.booking__ds__extract_month
+ , subq_0.booking__ds__extract_day
+ , subq_0.booking__ds__extract_dow
+ , subq_0.booking__ds__extract_doy
+ , subq_0.booking__ds_partitioned__day
+ , subq_0.booking__ds_partitioned__week
+ , subq_0.booking__ds_partitioned__month
+ , subq_0.booking__ds_partitioned__quarter
+ , subq_0.booking__ds_partitioned__year
+ , subq_0.booking__ds_partitioned__extract_year
+ , subq_0.booking__ds_partitioned__extract_quarter
+ , subq_0.booking__ds_partitioned__extract_month
+ , subq_0.booking__ds_partitioned__extract_day
+ , subq_0.booking__ds_partitioned__extract_dow
+ , subq_0.booking__ds_partitioned__extract_doy
+ , subq_0.booking__paid_at__day
+ , subq_0.booking__paid_at__week
+ , subq_0.booking__paid_at__month
+ , subq_0.booking__paid_at__quarter
+ , subq_0.booking__paid_at__year
+ , subq_0.booking__paid_at__extract_year
+ , subq_0.booking__paid_at__extract_quarter
+ , subq_0.booking__paid_at__extract_month
+ , subq_0.booking__paid_at__extract_day
+ , subq_0.booking__paid_at__extract_dow
+ , subq_0.booking__paid_at__extract_doy
+ , subq_0.ds__day AS metric_time__day
+ , subq_0.ds__week AS metric_time__week
+ , subq_0.ds__month AS metric_time__month
+ , subq_0.ds__quarter AS metric_time__quarter
+ , subq_0.ds__year AS metric_time__year
+ , subq_0.ds__extract_year AS metric_time__extract_year
+ , subq_0.ds__extract_quarter AS metric_time__extract_quarter
+ , subq_0.ds__extract_month AS metric_time__extract_month
+ , subq_0.ds__extract_day AS metric_time__extract_day
+ , subq_0.ds__extract_dow AS metric_time__extract_dow
+ , subq_0.ds__extract_doy AS metric_time__extract_doy
+ , subq_0.listing
+ , subq_0.guest
+ , subq_0.host
+ , subq_0.booking__listing
+ , subq_0.booking__guest
+ , subq_0.booking__host
+ , subq_0.is_instant
+ , subq_0.booking__is_instant
+ , subq_0.bookings
+ , subq_0.instant_bookings
+ , subq_0.booking_value
+ , subq_0.max_booking_value
+ , subq_0.min_booking_value
+ , subq_0.bookers
+ , subq_0.average_booking_value
+ , subq_0.referred_bookings
+ , subq_0.median_booking_value
+ , subq_0.booking_value_p99
+ , subq_0.discrete_booking_value_p99
+ , subq_0.approximate_continuous_booking_value_p99
+ , subq_0.approximate_discrete_booking_value_p99
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ SELECT
+ 1 AS bookings
+ , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings
+ , bookings_source_src_10001.booking_value
+ , bookings_source_src_10001.booking_value AS max_booking_value
+ , bookings_source_src_10001.booking_value AS min_booking_value
+ , bookings_source_src_10001.guest_id AS bookers
+ , bookings_source_src_10001.booking_value AS average_booking_value
+ , bookings_source_src_10001.booking_value AS booking_payments
+ , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings
+ , bookings_source_src_10001.booking_value AS median_booking_value
+ , bookings_source_src_10001.booking_value AS booking_value_p99
+ , bookings_source_src_10001.booking_value AS discrete_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_continuous_booking_value_p99
+ , bookings_source_src_10001.booking_value AS approximate_discrete_booking_value_p99
+ , bookings_source_src_10001.is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS paid_at__extract_doy
+ , bookings_source_src_10001.is_instant AS booking__is_instant
+ , DATE_TRUNC('day', bookings_source_src_10001.ds) AS booking__ds__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds) AS booking__ds__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds) AS booking__ds__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds) AS booking__ds__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds) AS booking__ds__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds) AS booking__ds__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds) AS booking__ds__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds) AS booking__ds__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds) AS booking__ds__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds) AS booking__ds__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds) AS booking__ds__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__day
+ , DATE_TRUNC('week', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__week
+ , DATE_TRUNC('month', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__year
+ , EXTRACT(year FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.ds_partitioned) AS booking__ds_partitioned__extract_doy
+ , DATE_TRUNC('day', bookings_source_src_10001.paid_at) AS booking__paid_at__day
+ , DATE_TRUNC('week', bookings_source_src_10001.paid_at) AS booking__paid_at__week
+ , DATE_TRUNC('month', bookings_source_src_10001.paid_at) AS booking__paid_at__month
+ , DATE_TRUNC('quarter', bookings_source_src_10001.paid_at) AS booking__paid_at__quarter
+ , DATE_TRUNC('year', bookings_source_src_10001.paid_at) AS booking__paid_at__year
+ , EXTRACT(year FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_year
+ , EXTRACT(quarter FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_quarter
+ , EXTRACT(month FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_month
+ , EXTRACT(day FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_day
+ , EXTRACT(DAY_OF_WEEK FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_dow
+ , EXTRACT(doy FROM bookings_source_src_10001.paid_at) AS booking__paid_at__extract_doy
+ , bookings_source_src_10001.listing_id AS listing
+ , bookings_source_src_10001.guest_id AS guest
+ , bookings_source_src_10001.host_id AS host
+ , bookings_source_src_10001.listing_id AS booking__listing
+ , bookings_source_src_10001.guest_id AS booking__guest
+ , bookings_source_src_10001.host_id AS booking__host
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_0
+ ) subq_1
+ ) subq_2
+ GROUP BY
+ subq_2.metric_time__day
+ ) subq_3
+ ON
+ subq_4.metric_time__day = subq_3.metric_time__day
+) subq_6
diff --git a/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql b/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql
new file mode 100644
index 0000000000..cc3c93f375
--- /dev/null
+++ b/metricflow/test/snapshots/test_time_spine_join_rendering.py/SqlQueryPlan/Trino/test_simple_join_to_time_spine__plan0_optimized.sql
@@ -0,0 +1,26 @@
+-- Join to Time Spine Dataset
+-- Compute Metrics via Expressions
+SELECT
+ subq_12.ds AS metric_time__day
+ , subq_10.bookings AS bookings_join_to_time_spine
+FROM ***************************.mf_time_spine subq_12
+LEFT OUTER JOIN (
+ -- Aggregate Measures
+ SELECT
+ metric_time__day
+ , SUM(bookings) AS bookings
+ FROM (
+ -- Read Elements From Semantic Model 'bookings_source'
+ -- Metric Time Dimension 'ds'
+ -- Pass Only Elements:
+ -- ['bookings', 'metric_time__day']
+ SELECT
+ DATE_TRUNC('day', ds) AS metric_time__day
+ , 1 AS bookings
+ FROM ***************************.fct_bookings bookings_source_src_10001
+ ) subq_9
+ GROUP BY
+ metric_time__day
+) subq_10
+ON
+ subq_12.ds = subq_10.metric_time__day
diff --git a/pyproject.toml b/pyproject.toml
index 9f77994289..7a36838646 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -11,7 +11,7 @@ requires-python = ">=3.8,<3.12"
license = "BUSL-1.1"
keywords = []
authors = [
- {name = "dbt Labs"}
+ {name = "dbt Labs"}
]
classifiers = [
@@ -72,6 +72,9 @@ sql-client-packages = [
"SQLAlchemy~=1.4.42",
"sqlalchemy2-stubs~=0.0.2a21",
]
+trino-sql-client-packages = [
+ "trino~=0.327.0",
+]
dbt-postgres = [
"dbt-postgres~=1.7.0",
@@ -97,6 +100,10 @@ dbt-duckdb = [
"dbt-duckdb~=1.7.0",
]
+dbt-trino = [
+ "dbt-trino~=1.7.0",
+]
+
[tool.hatch.build.targets.sdist]
exclude = [
"/.github",
@@ -118,13 +125,13 @@ features = [
]
[tool.hatch.envs.dev-env.env-vars]
- MF_TEST_ADAPTER_TYPE="duckdb"
- MF_SQL_ENGINE_URL="duckdb://"
+MF_TEST_ADAPTER_TYPE="duckdb"
+MF_SQL_ENGINE_URL="duckdb://"
[tool.hatch.envs.postgres-env.env-vars]
- MF_SQL_ENGINE_URL="postgresql://metricflow@localhost:5432/metricflow"
- MF_SQL_ENGINE_PASSWORD="metricflowing"
- MF_TEST_ADAPTER_TYPE="postgres"
+MF_SQL_ENGINE_URL="postgresql://metricflow@localhost:5432/metricflow"
+MF_SQL_ENGINE_PASSWORD="metricflowing"
+MF_TEST_ADAPTER_TYPE="postgres"
[tool.hatch.envs.postgres-env]
description = "Dev environment for working with Postgres adapter"
@@ -138,7 +145,7 @@ features = [
# configured independently of the hatch env construction
[tool.hatch.envs.bigquery-env.env-vars]
- MF_TEST_ADAPTER_TYPE="bigquery"
+MF_TEST_ADAPTER_TYPE="bigquery"
[tool.hatch.envs.bigquery-env]
description = "Dev environment for working with the BigQuery adapter"
@@ -149,7 +156,7 @@ features = [
]
[tool.hatch.envs.databricks-env.env-vars]
- MF_TEST_ADAPTER_TYPE="databricks"
+MF_TEST_ADAPTER_TYPE="databricks"
[tool.hatch.envs.databricks-env]
description = "Dev environment for working with the Databricks adapter"
@@ -160,7 +167,7 @@ features = [
]
[tool.hatch.envs.redshift-env.env-vars]
- MF_TEST_ADAPTER_TYPE="redshift"
+MF_TEST_ADAPTER_TYPE="redshift"
[tool.hatch.envs.redshift-env]
description = "Dev environment for working with the Redshift adapter"
@@ -171,7 +178,7 @@ features = [
]
[tool.hatch.envs.snowflake-env.env-vars]
- MF_TEST_ADAPTER_TYPE="snowflake"
+MF_TEST_ADAPTER_TYPE="snowflake"
[tool.hatch.envs.snowflake-env]
description = "Dev environment for working with Snowflake adapter"
@@ -181,6 +188,20 @@ features = [
"sql-client-packages",
]
+[tool.hatch.envs.trino-env.env-vars]
+MF_TEST_ADAPTER_TYPE = "trino"
+MF_SQL_ENGINE_URL = "trino://trino@localhost:8080/"
+DBT_ENV_SECRET_CATALOG="memory"
+
+[tool.hatch.envs.trino-env]
+description = "Dev environment for working with the Trino adapter"
+features = [
+ "dev-packages",
+ "dbt-trino",
+ "sql-client-packages",
+ "trino-sql-client-packages",
+]
+
[tool.black]
line-length = 120
@@ -189,7 +210,7 @@ line-length = 120
# warnings.
[tool.pytest.ini_options]
filterwarnings = [
- "ignore:Deprecated call to.*",
- "ignore:pkg_resources is deprecated as an API"
+ "ignore:Deprecated call to.*",
+ "ignore:pkg_resources is deprecated as an API"
]
python_functions = "test_* populate_source_schema"