diff --git a/metricflow/test/integration/test_rendered_query.py b/metricflow/test/integration/test_rendered_query.py index 20eced440f..0234f4a026 100644 --- a/metricflow/test/integration/test_rendered_query.py +++ b/metricflow/test/integration/test_rendered_query.py @@ -2,14 +2,19 @@ import pytest from _pytest.fixtures import FixtureRequest +from dbt_semantic_interfaces.test_utils import as_datetime from metricflow.dataflow.sql_table import SqlTable -from metricflow.engine.metricflow_engine import MetricFlowQueryRequest +from metricflow.engine.metricflow_engine import MetricFlowEngine, MetricFlowQueryRequest +from metricflow.model.semantic_manifest_lookup import SemanticManifestLookup +from metricflow.plan_conversion.column_resolver import DunderColumnAssociationResolver +from metricflow.protocols.sql_client import SqlClient from metricflow.test.fixtures.setup_fixtures import MetricFlowTestSessionState from metricflow.test.integration.conftest import IntegrationTestHelpers from metricflow.test.snapshot_utils import ( assert_sql_snapshot_equal, ) +from metricflow.test.time.configurable_time_source import ConfigurableTimeSource @pytest.mark.sql_engine_snapshot @@ -51,3 +56,102 @@ def test_render_write_to_table_query( # noqa: D sql=result.rendered_sql.sql_query, sql_engine=it_helpers.sql_client.sql_engine_type, ) + + +@pytest.mark.sql_engine_snapshot +def test_id_enumeration( # noqa: D + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + simple_semantic_manifest_lookup: SemanticManifestLookup, + sql_client: SqlClient, +) -> None: + mf_engine = MetricFlowEngine( + semantic_manifest_lookup=simple_semantic_manifest_lookup, + sql_client=sql_client, + column_association_resolver=DunderColumnAssociationResolver( + semantic_manifest_lookup=simple_semantic_manifest_lookup + ), + time_source=ConfigurableTimeSource(as_datetime("2020-01-01")), + consistent_id_enumeration=True, + ) + + result = mf_engine.explain( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=["bookings", "listings"], + group_by_names=["metric_time"], + ) + ) + + assert_sql_snapshot_equal( + request=request, + mf_test_session_state=mf_test_session_state, + snapshot_id="query", + sql=result.rendered_sql.sql_query, + sql_engine=sql_client.sql_engine_type, + ) + + # The resulting snapshot should be the same since mf_engine was created with consistent_id_enumeration=True + result = mf_engine.explain( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=["bookings", "listings"], + group_by_names=["metric_time"], + ) + ) + + assert_sql_snapshot_equal( + request=request, + mf_test_session_state=mf_test_session_state, + snapshot_id="query", + sql=result.rendered_sql.sql_query, + sql_engine=sql_client.sql_engine_type, + ) + + +@pytest.mark.sql_engine_snapshot +def test_id_enumeration_without_consistency_flag( + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + simple_semantic_manifest_lookup: SemanticManifestLookup, + sql_client: SqlClient, +) -> None: + """Test generated SQL with consistent_id_enumeration=False.""" + mf_engine = MetricFlowEngine( + semantic_manifest_lookup=simple_semantic_manifest_lookup, + sql_client=sql_client, + column_association_resolver=DunderColumnAssociationResolver( + semantic_manifest_lookup=simple_semantic_manifest_lookup + ), + time_source=ConfigurableTimeSource(as_datetime("2020-01-01")), + consistent_id_enumeration=False, + ) + + result = mf_engine.explain( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=["bookings", "listings"], + group_by_names=["metric_time"], + ) + ) + + assert_sql_snapshot_equal( + request=request, + mf_test_session_state=mf_test_session_state, + snapshot_id="first_query", + sql=result.rendered_sql.sql_query, + sql_engine=sql_client.sql_engine_type, + ) + + # The second set of queries should have IDs that are sequentially numbered with respect to the previous query. + result = mf_engine.explain( + MetricFlowQueryRequest.create_with_random_request_id( + metric_names=["bookings", "listings"], + group_by_names=["metric_time"], + ) + ) + + assert_sql_snapshot_equal( + request=request, + mf_test_session_state=mf_test_session_state, + snapshot_id="second_query", + sql=result.rendered_sql.sql_query, + sql_engine=sql_client.sql_engine_type, + ) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/BigQuery/test_id_enumeration__query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/BigQuery/test_id_enumeration__query.sql new file mode 100644 index 0000000000..b2473e6773 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/BigQuery/test_id_enumeration__query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day + , MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC(ds, day) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_2 + GROUP BY + metric_time__day +) subq_4 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC(created_at, day) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_7 + GROUP BY + metric_time__day +) subq_9 +ON + subq_4.metric_time__day = subq_9.metric_time__day +GROUP BY + metric_time__day diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/BigQuery/test_id_enumeration_without_consistency_flag__first_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/BigQuery/test_id_enumeration_without_consistency_flag__first_query.sql new file mode 100644 index 0000000000..3ca789ff25 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/BigQuery/test_id_enumeration_without_consistency_flag__first_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) AS metric_time__day + , MAX(subq_10013.bookings) AS bookings + , MAX(subq_10018.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC(ds, day) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10011 + GROUP BY + metric_time__day +) subq_10013 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC(created_at, day) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10016 + GROUP BY + metric_time__day +) subq_10018 +ON + subq_10013.metric_time__day = subq_10018.metric_time__day +GROUP BY + metric_time__day diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/BigQuery/test_id_enumeration_without_consistency_flag__second_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/BigQuery/test_id_enumeration_without_consistency_flag__second_query.sql new file mode 100644 index 0000000000..6b6f009d1c --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/BigQuery/test_id_enumeration_without_consistency_flag__second_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) AS metric_time__day + , MAX(subq_10023.bookings) AS bookings + , MAX(subq_10028.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC(ds, day) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10021 + GROUP BY + metric_time__day +) subq_10023 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC(created_at, day) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10026 + GROUP BY + metric_time__day +) subq_10028 +ON + subq_10023.metric_time__day = subq_10028.metric_time__day +GROUP BY + metric_time__day diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Databricks/test_id_enumeration__query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Databricks/test_id_enumeration__query.sql new file mode 100644 index 0000000000..afe59d05cf --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Databricks/test_id_enumeration__query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day + , MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_2 + GROUP BY + metric_time__day +) subq_4 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_7 + GROUP BY + metric_time__day +) subq_9 +ON + subq_4.metric_time__day = subq_9.metric_time__day +GROUP BY + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Databricks/test_id_enumeration_without_consistency_flag__first_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Databricks/test_id_enumeration_without_consistency_flag__first_query.sql new file mode 100644 index 0000000000..e1be735679 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Databricks/test_id_enumeration_without_consistency_flag__first_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) AS metric_time__day + , MAX(subq_10013.bookings) AS bookings + , MAX(subq_10018.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10011 + GROUP BY + metric_time__day +) subq_10013 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10016 + GROUP BY + metric_time__day +) subq_10018 +ON + subq_10013.metric_time__day = subq_10018.metric_time__day +GROUP BY + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Databricks/test_id_enumeration_without_consistency_flag__second_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Databricks/test_id_enumeration_without_consistency_flag__second_query.sql new file mode 100644 index 0000000000..2b3cc9aec3 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Databricks/test_id_enumeration_without_consistency_flag__second_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) AS metric_time__day + , MAX(subq_10023.bookings) AS bookings + , MAX(subq_10028.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10021 + GROUP BY + metric_time__day +) subq_10023 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10026 + GROUP BY + metric_time__day +) subq_10028 +ON + subq_10023.metric_time__day = subq_10028.metric_time__day +GROUP BY + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration__query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration__query.sql new file mode 100644 index 0000000000..afe59d05cf --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration__query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day + , MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_2 + GROUP BY + metric_time__day +) subq_4 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_7 + GROUP BY + metric_time__day +) subq_9 +ON + subq_4.metric_time__day = subq_9.metric_time__day +GROUP BY + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration_without_consistency_flag__first_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration_without_consistency_flag__first_query.sql new file mode 100644 index 0000000000..e1be735679 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration_without_consistency_flag__first_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) AS metric_time__day + , MAX(subq_10013.bookings) AS bookings + , MAX(subq_10018.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10011 + GROUP BY + metric_time__day +) subq_10013 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10016 + GROUP BY + metric_time__day +) subq_10018 +ON + subq_10013.metric_time__day = subq_10018.metric_time__day +GROUP BY + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration_without_consistency_flag__second_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration_without_consistency_flag__second_query.sql new file mode 100644 index 0000000000..2b3cc9aec3 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration_without_consistency_flag__second_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) AS metric_time__day + , MAX(subq_10023.bookings) AS bookings + , MAX(subq_10028.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10021 + GROUP BY + metric_time__day +) subq_10023 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10026 + GROUP BY + metric_time__day +) subq_10028 +ON + subq_10023.metric_time__day = subq_10028.metric_time__day +GROUP BY + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Postgres/test_id_enumeration__query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Postgres/test_id_enumeration__query.sql new file mode 100644 index 0000000000..afe59d05cf --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Postgres/test_id_enumeration__query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day + , MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_2 + GROUP BY + metric_time__day +) subq_4 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_7 + GROUP BY + metric_time__day +) subq_9 +ON + subq_4.metric_time__day = subq_9.metric_time__day +GROUP BY + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Postgres/test_id_enumeration_without_consistency_flag__first_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Postgres/test_id_enumeration_without_consistency_flag__first_query.sql new file mode 100644 index 0000000000..e1be735679 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Postgres/test_id_enumeration_without_consistency_flag__first_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) AS metric_time__day + , MAX(subq_10013.bookings) AS bookings + , MAX(subq_10018.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10011 + GROUP BY + metric_time__day +) subq_10013 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10016 + GROUP BY + metric_time__day +) subq_10018 +ON + subq_10013.metric_time__day = subq_10018.metric_time__day +GROUP BY + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Postgres/test_id_enumeration_without_consistency_flag__second_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Postgres/test_id_enumeration_without_consistency_flag__second_query.sql new file mode 100644 index 0000000000..2b3cc9aec3 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Postgres/test_id_enumeration_without_consistency_flag__second_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) AS metric_time__day + , MAX(subq_10023.bookings) AS bookings + , MAX(subq_10028.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10021 + GROUP BY + metric_time__day +) subq_10023 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10026 + GROUP BY + metric_time__day +) subq_10028 +ON + subq_10023.metric_time__day = subq_10028.metric_time__day +GROUP BY + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Redshift/test_id_enumeration__query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Redshift/test_id_enumeration__query.sql new file mode 100644 index 0000000000..afe59d05cf --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Redshift/test_id_enumeration__query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day + , MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_2 + GROUP BY + metric_time__day +) subq_4 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_7 + GROUP BY + metric_time__day +) subq_9 +ON + subq_4.metric_time__day = subq_9.metric_time__day +GROUP BY + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Redshift/test_id_enumeration_without_consistency_flag__first_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Redshift/test_id_enumeration_without_consistency_flag__first_query.sql new file mode 100644 index 0000000000..e1be735679 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Redshift/test_id_enumeration_without_consistency_flag__first_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) AS metric_time__day + , MAX(subq_10013.bookings) AS bookings + , MAX(subq_10018.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10011 + GROUP BY + metric_time__day +) subq_10013 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10016 + GROUP BY + metric_time__day +) subq_10018 +ON + subq_10013.metric_time__day = subq_10018.metric_time__day +GROUP BY + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Redshift/test_id_enumeration_without_consistency_flag__second_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Redshift/test_id_enumeration_without_consistency_flag__second_query.sql new file mode 100644 index 0000000000..2b3cc9aec3 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Redshift/test_id_enumeration_without_consistency_flag__second_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) AS metric_time__day + , MAX(subq_10023.bookings) AS bookings + , MAX(subq_10028.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10021 + GROUP BY + metric_time__day +) subq_10023 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10026 + GROUP BY + metric_time__day +) subq_10028 +ON + subq_10023.metric_time__day = subq_10028.metric_time__day +GROUP BY + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Snowflake/test_id_enumeration__query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Snowflake/test_id_enumeration__query.sql new file mode 100644 index 0000000000..afe59d05cf --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Snowflake/test_id_enumeration__query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day + , MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_2 + GROUP BY + metric_time__day +) subq_4 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_7 + GROUP BY + metric_time__day +) subq_9 +ON + subq_4.metric_time__day = subq_9.metric_time__day +GROUP BY + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Snowflake/test_id_enumeration_without_consistency_flag__first_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Snowflake/test_id_enumeration_without_consistency_flag__first_query.sql new file mode 100644 index 0000000000..e1be735679 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Snowflake/test_id_enumeration_without_consistency_flag__first_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) AS metric_time__day + , MAX(subq_10013.bookings) AS bookings + , MAX(subq_10018.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10011 + GROUP BY + metric_time__day +) subq_10013 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10016 + GROUP BY + metric_time__day +) subq_10018 +ON + subq_10013.metric_time__day = subq_10018.metric_time__day +GROUP BY + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Snowflake/test_id_enumeration_without_consistency_flag__second_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Snowflake/test_id_enumeration_without_consistency_flag__second_query.sql new file mode 100644 index 0000000000..2b3cc9aec3 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Snowflake/test_id_enumeration_without_consistency_flag__second_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) AS metric_time__day + , MAX(subq_10023.bookings) AS bookings + , MAX(subq_10028.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10021 + GROUP BY + metric_time__day +) subq_10023 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10026 + GROUP BY + metric_time__day +) subq_10028 +ON + subq_10023.metric_time__day = subq_10028.metric_time__day +GROUP BY + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Trino/test_id_enumeration__query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Trino/test_id_enumeration__query.sql new file mode 100644 index 0000000000..afe59d05cf --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Trino/test_id_enumeration__query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day + , MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_2 + GROUP BY + metric_time__day +) subq_4 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_7 + GROUP BY + metric_time__day +) subq_9 +ON + subq_4.metric_time__day = subq_9.metric_time__day +GROUP BY + COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Trino/test_id_enumeration_without_consistency_flag__first_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Trino/test_id_enumeration_without_consistency_flag__first_query.sql new file mode 100644 index 0000000000..e1be735679 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Trino/test_id_enumeration_without_consistency_flag__first_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) AS metric_time__day + , MAX(subq_10013.bookings) AS bookings + , MAX(subq_10018.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10011 + GROUP BY + metric_time__day +) subq_10013 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10016 + GROUP BY + metric_time__day +) subq_10018 +ON + subq_10013.metric_time__day = subq_10018.metric_time__day +GROUP BY + COALESCE(subq_10013.metric_time__day, subq_10018.metric_time__day) diff --git a/metricflow/test/snapshots/test_rendered_query.py/str/Trino/test_id_enumeration_without_consistency_flag__second_query.sql b/metricflow/test/snapshots/test_rendered_query.py/str/Trino/test_id_enumeration_without_consistency_flag__second_query.sql new file mode 100644 index 0000000000..2b3cc9aec3 --- /dev/null +++ b/metricflow/test/snapshots/test_rendered_query.py/str/Trino/test_id_enumeration_without_consistency_flag__second_query.sql @@ -0,0 +1,45 @@ +-- Combine Aggregated Outputs +SELECT + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day) AS metric_time__day + , MAX(subq_10023.bookings) AS bookings + , MAX(subq_10028.listings) AS listings +FROM ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(bookings) AS bookings + FROM ( + -- Read Elements From Semantic Model 'bookings_source' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', ds) AS metric_time__day + , 1 AS bookings + FROM ***************************.fct_bookings bookings_source_src_10000 + ) subq_10021 + GROUP BY + metric_time__day +) subq_10023 +FULL OUTER JOIN ( + -- Aggregate Measures + -- Compute Metrics via Expressions + SELECT + metric_time__day + , SUM(listings) AS listings + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day'] + SELECT + DATE_TRUNC('day', created_at) AS metric_time__day + , 1 AS listings + FROM ***************************.dim_listings_latest listings_latest_src_10000 + ) subq_10026 + GROUP BY + metric_time__day +) subq_10028 +ON + subq_10023.metric_time__day = subq_10028.metric_time__day +GROUP BY + COALESCE(subq_10023.metric_time__day, subq_10028.metric_time__day)