From 3c63c48e1efd557e9e63bd862a5e7acb4d22d7bc Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Wed, 28 Aug 2024 11:39:00 -0700 Subject: [PATCH] Add SQL rendering test And update snapshots --- .../query_rendering/test_query_rendering.py | 23 ++ ...imension_with_non_default_grain__plan0.sql | 230 ++++++++++++++++++ ...ith_non_default_grain__plan0_optimized.sql | 26 ++ ...imension_with_non_default_grain__plan0.sql | 230 ++++++++++++++++++ ...ith_non_default_grain__plan0_optimized.sql | 26 ++ ...imension_with_non_default_grain__plan0.sql | 230 ++++++++++++++++++ ...ith_non_default_grain__plan0_optimized.sql | 26 ++ ...imension_with_non_default_grain__plan0.sql | 230 ++++++++++++++++++ ...ith_non_default_grain__plan0_optimized.sql | 26 ++ ...imension_with_non_default_grain__plan0.sql | 230 ++++++++++++++++++ ...ith_non_default_grain__plan0_optimized.sql | 26 ++ ...imension_with_non_default_grain__plan0.sql | 230 ++++++++++++++++++ ...ith_non_default_grain__plan0_optimized.sql | 26 ++ ...imension_with_non_default_grain__plan0.sql | 230 ++++++++++++++++++ ...ith_non_default_grain__plan0_optimized.sql | 26 ++ 15 files changed, 1815 insertions(+) create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_non_additive_dimension_with_non_default_grain__plan0.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_non_additive_dimension_with_non_default_grain__plan0.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_non_additive_dimension_with_non_default_grain__plan0.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_non_additive_dimension_with_non_default_grain__plan0.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_non_additive_dimension_with_non_default_grain__plan0.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_non_additive_dimension_with_non_default_grain__plan0.sql create mode 100644 tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql diff --git a/tests_metricflow/query_rendering/test_query_rendering.py b/tests_metricflow/query_rendering/test_query_rendering.py index b96c5786d2..b4398a0335 100644 --- a/tests_metricflow/query_rendering/test_query_rendering.py +++ b/tests_metricflow/query_rendering/test_query_rendering.py @@ -565,3 +565,26 @@ def test_min_max_metric_time_week( dataflow_plan_builder=dataflow_plan_builder, query_spec=query_spec, ) + + +@pytest.mark.sql_engine_snapshot +def test_non_additive_dimension_with_non_default_grain( + request: FixtureRequest, + mf_test_configuration: MetricFlowTestConfiguration, + dataflow_plan_builder: DataflowPlanBuilder, + sql_client: SqlClient, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, +) -> None: + """Tests querying a metric with a non-additive agg_time_dimension that has non-default granularity.""" + query_spec = MetricFlowQuerySpec( + metric_specs=(MetricSpec(element_name="total_account_balance_first_day_of_month"),) + ) + + render_and_check( + request=request, + mf_test_configuration=mf_test_configuration, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + dataflow_plan_builder=dataflow_plan_builder, + query_spec=query_spec, + ) diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_non_additive_dimension_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_non_additive_dimension_with_non_default_grain__plan0.sql new file mode 100644 index 0000000000..bf796aec43 --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_non_additive_dimension_with_non_default_grain__plan0.sql @@ -0,0 +1,230 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.total_account_balance_first_day_of_month +FROM ( + -- Aggregate Measures + SELECT + SUM(subq_6.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month',] + SELECT + subq_5.total_account_balance_first_day_of_month + FROM ( + -- Join on MIN(ds_month) and [] grouping by None + SELECT + subq_2.ds_month__month AS ds_month__month + , subq_2.total_account_balance_first_day_of_month AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, month) AS ds_month__month + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, quarter) AS ds_month__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, year) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS account__ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS account__ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS account__ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS account__ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS account__ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, month) AS account__ds_month__month + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, quarter) AS account__ds_month__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, year) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + INNER JOIN ( + -- Filter row on MIN(ds_month__month) + SELECT + MIN(subq_3.ds_month__month) AS ds_month__month__complete + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, month) AS ds_month__month + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, quarter) AS ds_month__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, year) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATETIME_TRUNC(accounts_source_src_28000.ds, day) AS account__ds__day + , DATETIME_TRUNC(accounts_source_src_28000.ds, isoweek) AS account__ds__week + , DATETIME_TRUNC(accounts_source_src_28000.ds, month) AS account__ds__month + , DATETIME_TRUNC(accounts_source_src_28000.ds, quarter) AS account__ds__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds, year) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , IF(EXTRACT(dayofweek FROM accounts_source_src_28000.ds) = 1, 7, EXTRACT(dayofweek FROM accounts_source_src_28000.ds) - 1) AS account__ds__extract_dow + , EXTRACT(dayofyear FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, month) AS account__ds_month__month + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, quarter) AS account__ds_month__quarter + , DATETIME_TRUNC(accounts_source_src_28000.ds_month, year) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_3 + ) subq_4 + ON + subq_2.ds_month__month = subq_4.ds_month__month__complete + ) subq_5 + ) subq_6 +) subq_7 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql new file mode 100644 index 0000000000..97055bf54c --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/BigQuery/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql @@ -0,0 +1,26 @@ +-- Join on MIN(ds_month) and [] grouping by None +-- Pass Only Elements: ['total_account_balance_first_day_of_month',] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + SUM(subq_10.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + DATETIME_TRUNC(ds_month, month) AS ds_month__month + , account_balance AS total_account_balance_first_day_of_month + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_10 +INNER JOIN ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + -- Filter row on MIN(ds_month__month) + SELECT + MIN(DATETIME_TRUNC(ds_month, month)) AS ds_month__month__complete + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_12 +ON + subq_10.ds_month__month = subq_12.ds_month__month__complete diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_non_additive_dimension_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_non_additive_dimension_with_non_default_grain__plan0.sql new file mode 100644 index 0000000000..308afbf3dd --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_non_additive_dimension_with_non_default_grain__plan0.sql @@ -0,0 +1,230 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.total_account_balance_first_day_of_month +FROM ( + -- Aggregate Measures + SELECT + SUM(subq_6.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month',] + SELECT + subq_5.total_account_balance_first_day_of_month + FROM ( + -- Join on MIN(ds_month) and [] grouping by None + SELECT + subq_2.ds_month__month AS ds_month__month + , subq_2.total_account_balance_first_day_of_month AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + INNER JOIN ( + -- Filter row on MIN(ds_month__month) + SELECT + MIN(subq_3.ds_month__month) AS ds_month__month__complete + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_3 + ) subq_4 + ON + subq_2.ds_month__month = subq_4.ds_month__month__complete + ) subq_5 + ) subq_6 +) subq_7 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql new file mode 100644 index 0000000000..90b981493f --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Databricks/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql @@ -0,0 +1,26 @@ +-- Join on MIN(ds_month) and [] grouping by None +-- Pass Only Elements: ['total_account_balance_first_day_of_month',] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + SUM(subq_10.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + DATE_TRUNC('month', ds_month) AS ds_month__month + , account_balance AS total_account_balance_first_day_of_month + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_10 +INNER JOIN ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + -- Filter row on MIN(ds_month__month) + SELECT + MIN(DATE_TRUNC('month', ds_month)) AS ds_month__month__complete + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_12 +ON + subq_10.ds_month__month = subq_12.ds_month__month__complete diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0.sql new file mode 100644 index 0000000000..c4eac70b4c --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0.sql @@ -0,0 +1,230 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.total_account_balance_first_day_of_month +FROM ( + -- Aggregate Measures + SELECT + SUM(subq_6.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month',] + SELECT + subq_5.total_account_balance_first_day_of_month + FROM ( + -- Join on MIN(ds_month) and [] grouping by None + SELECT + subq_2.ds_month__month AS ds_month__month + , subq_2.total_account_balance_first_day_of_month AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + INNER JOIN ( + -- Filter row on MIN(ds_month__month) + SELECT + MIN(subq_3.ds_month__month) AS ds_month__month__complete + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_3 + ) subq_4 + ON + subq_2.ds_month__month = subq_4.ds_month__month__complete + ) subq_5 + ) subq_6 +) subq_7 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql new file mode 100644 index 0000000000..90b981493f --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql @@ -0,0 +1,26 @@ +-- Join on MIN(ds_month) and [] grouping by None +-- Pass Only Elements: ['total_account_balance_first_day_of_month',] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + SUM(subq_10.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + DATE_TRUNC('month', ds_month) AS ds_month__month + , account_balance AS total_account_balance_first_day_of_month + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_10 +INNER JOIN ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + -- Filter row on MIN(ds_month__month) + SELECT + MIN(DATE_TRUNC('month', ds_month)) AS ds_month__month__complete + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_12 +ON + subq_10.ds_month__month = subq_12.ds_month__month__complete diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_non_additive_dimension_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_non_additive_dimension_with_non_default_grain__plan0.sql new file mode 100644 index 0000000000..c4eac70b4c --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_non_additive_dimension_with_non_default_grain__plan0.sql @@ -0,0 +1,230 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.total_account_balance_first_day_of_month +FROM ( + -- Aggregate Measures + SELECT + SUM(subq_6.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month',] + SELECT + subq_5.total_account_balance_first_day_of_month + FROM ( + -- Join on MIN(ds_month) and [] grouping by None + SELECT + subq_2.ds_month__month AS ds_month__month + , subq_2.total_account_balance_first_day_of_month AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + INNER JOIN ( + -- Filter row on MIN(ds_month__month) + SELECT + MIN(subq_3.ds_month__month) AS ds_month__month__complete + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_3 + ) subq_4 + ON + subq_2.ds_month__month = subq_4.ds_month__month__complete + ) subq_5 + ) subq_6 +) subq_7 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql new file mode 100644 index 0000000000..90b981493f --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Postgres/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql @@ -0,0 +1,26 @@ +-- Join on MIN(ds_month) and [] grouping by None +-- Pass Only Elements: ['total_account_balance_first_day_of_month',] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + SUM(subq_10.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + DATE_TRUNC('month', ds_month) AS ds_month__month + , account_balance AS total_account_balance_first_day_of_month + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_10 +INNER JOIN ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + -- Filter row on MIN(ds_month__month) + SELECT + MIN(DATE_TRUNC('month', ds_month)) AS ds_month__month__complete + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_12 +ON + subq_10.ds_month__month = subq_12.ds_month__month__complete diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_non_additive_dimension_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_non_additive_dimension_with_non_default_grain__plan0.sql new file mode 100644 index 0000000000..df5d0dfc59 --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_non_additive_dimension_with_non_default_grain__plan0.sql @@ -0,0 +1,230 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.total_account_balance_first_day_of_month +FROM ( + -- Aggregate Measures + SELECT + SUM(subq_6.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month',] + SELECT + subq_5.total_account_balance_first_day_of_month + FROM ( + -- Join on MIN(ds_month) and [] grouping by None + SELECT + subq_2.ds_month__month AS ds_month__month + , subq_2.total_account_balance_first_day_of_month AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + INNER JOIN ( + -- Filter row on MIN(ds_month__month) + SELECT + MIN(subq_3.ds_month__month) AS ds_month__month__complete + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , CASE WHEN EXTRACT(dow FROM accounts_source_src_28000.ds) = 0 THEN EXTRACT(dow FROM accounts_source_src_28000.ds) + 7 ELSE EXTRACT(dow FROM accounts_source_src_28000.ds) END AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_3 + ) subq_4 + ON + subq_2.ds_month__month = subq_4.ds_month__month__complete + ) subq_5 + ) subq_6 +) subq_7 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql new file mode 100644 index 0000000000..90b981493f --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Redshift/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql @@ -0,0 +1,26 @@ +-- Join on MIN(ds_month) and [] grouping by None +-- Pass Only Elements: ['total_account_balance_first_day_of_month',] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + SUM(subq_10.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + DATE_TRUNC('month', ds_month) AS ds_month__month + , account_balance AS total_account_balance_first_day_of_month + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_10 +INNER JOIN ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + -- Filter row on MIN(ds_month__month) + SELECT + MIN(DATE_TRUNC('month', ds_month)) AS ds_month__month__complete + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_12 +ON + subq_10.ds_month__month = subq_12.ds_month__month__complete diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_non_additive_dimension_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_non_additive_dimension_with_non_default_grain__plan0.sql new file mode 100644 index 0000000000..bc4617368b --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_non_additive_dimension_with_non_default_grain__plan0.sql @@ -0,0 +1,230 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.total_account_balance_first_day_of_month +FROM ( + -- Aggregate Measures + SELECT + SUM(subq_6.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month',] + SELECT + subq_5.total_account_balance_first_day_of_month + FROM ( + -- Join on MIN(ds_month) and [] grouping by None + SELECT + subq_2.ds_month__month AS ds_month__month + , subq_2.total_account_balance_first_day_of_month AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + INNER JOIN ( + -- Filter row on MIN(ds_month__month) + SELECT + MIN(subq_3.ds_month__month) AS ds_month__month__complete + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(dayofweekiso FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_3 + ) subq_4 + ON + subq_2.ds_month__month = subq_4.ds_month__month__complete + ) subq_5 + ) subq_6 +) subq_7 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql new file mode 100644 index 0000000000..90b981493f --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Snowflake/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql @@ -0,0 +1,26 @@ +-- Join on MIN(ds_month) and [] grouping by None +-- Pass Only Elements: ['total_account_balance_first_day_of_month',] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + SUM(subq_10.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + DATE_TRUNC('month', ds_month) AS ds_month__month + , account_balance AS total_account_balance_first_day_of_month + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_10 +INNER JOIN ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + -- Filter row on MIN(ds_month__month) + SELECT + MIN(DATE_TRUNC('month', ds_month)) AS ds_month__month__complete + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_12 +ON + subq_10.ds_month__month = subq_12.ds_month__month__complete diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_non_additive_dimension_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_non_additive_dimension_with_non_default_grain__plan0.sql new file mode 100644 index 0000000000..5b3083b605 --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_non_additive_dimension_with_non_default_grain__plan0.sql @@ -0,0 +1,230 @@ +-- Compute Metrics via Expressions +SELECT + subq_7.total_account_balance_first_day_of_month +FROM ( + -- Aggregate Measures + SELECT + SUM(subq_6.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month',] + SELECT + subq_5.total_account_balance_first_day_of_month + FROM ( + -- Join on MIN(ds_month) and [] grouping by None + SELECT + subq_2.ds_month__month AS ds_month__month + , subq_2.total_account_balance_first_day_of_month AS total_account_balance_first_day_of_month + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 + INNER JOIN ( + -- Filter row on MIN(ds_month__month) + SELECT + MIN(subq_3.ds_month__month) AS ds_month__month__complete + FROM ( + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + subq_1.ds_month__month + , subq_1.total_account_balance_first_day_of_month + FROM ( + -- Metric Time Dimension 'ds_month' + 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_month__month + , subq_0.ds_month__quarter + , subq_0.ds_month__year + , subq_0.ds_month__extract_year + , subq_0.ds_month__extract_quarter + , subq_0.ds_month__extract_month + , subq_0.account__ds__day + , subq_0.account__ds__week + , subq_0.account__ds__month + , subq_0.account__ds__quarter + , subq_0.account__ds__year + , subq_0.account__ds__extract_year + , subq_0.account__ds__extract_quarter + , subq_0.account__ds__extract_month + , subq_0.account__ds__extract_day + , subq_0.account__ds__extract_dow + , subq_0.account__ds__extract_doy + , subq_0.account__ds_month__month + , subq_0.account__ds_month__quarter + , subq_0.account__ds_month__year + , subq_0.account__ds_month__extract_year + , subq_0.account__ds_month__extract_quarter + , subq_0.account__ds_month__extract_month + , subq_0.ds_month__month AS metric_time__month + , subq_0.ds_month__quarter AS metric_time__quarter + , subq_0.ds_month__year AS metric_time__year + , subq_0.ds_month__extract_year AS metric_time__extract_year + , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter + , subq_0.ds_month__extract_month AS metric_time__extract_month + , subq_0.user + , subq_0.account__user + , subq_0.account_type + , subq_0.account__account_type + , subq_0.total_account_balance_first_day_of_month + FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(DAY_OF_WEEK FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_3 + ) subq_4 + ON + subq_2.ds_month__month = subq_4.ds_month__month__complete + ) subq_5 + ) subq_6 +) subq_7 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql new file mode 100644 index 0000000000..90b981493f --- /dev/null +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/Trino/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql @@ -0,0 +1,26 @@ +-- Join on MIN(ds_month) and [] grouping by None +-- Pass Only Elements: ['total_account_balance_first_day_of_month',] +-- Aggregate Measures +-- Compute Metrics via Expressions +SELECT + SUM(subq_10.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month +FROM ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + SELECT + DATE_TRUNC('month', ds_month) AS ds_month__month + , account_balance AS total_account_balance_first_day_of_month + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_10 +INNER JOIN ( + -- Read Elements From Semantic Model 'accounts_source' + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] + -- Filter row on MIN(ds_month__month) + SELECT + MIN(DATE_TRUNC('month', ds_month)) AS ds_month__month__complete + FROM ***************************.fct_accounts accounts_source_src_28000 +) subq_12 +ON + subq_10.ds_month__month = subq_12.ds_month__month__complete