From 0721d845a5a783594b7160b122e9795488c12477 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 28 Nov 2023 13:08:15 -0800 Subject: [PATCH 1/7] Move tests for distinct values to a separate file for better organization. --- .../test_distinct_values_to_sql.py | 38 +++++++++++++++++++ .../test_dataflow_to_sql_plan.py | 26 ------------- 2 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 metricflow/test/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py diff --git a/metricflow/test/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py b/metricflow/test/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py new file mode 100644 index 0000000000..1b365d693d --- /dev/null +++ b/metricflow/test/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py @@ -0,0 +1,38 @@ +from __future__ import annotations + +import pytest +from _pytest.fixtures import FixtureRequest +from dbt_semantic_interfaces.references import EntityReference + +from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder +from metricflow.plan_conversion.dataflow_to_sql import DataflowToSqlQueryPlanConverter +from metricflow.protocols.sql_client import SqlClient +from metricflow.specs.specs import DimensionSpec, MetricFlowQuerySpec +from metricflow.test.fixtures.setup_fixtures import MetricFlowTestSessionState +from metricflow.test.plan_conversion.test_dataflow_to_sql_plan import convert_and_check + + +@pytest.mark.sql_engine_snapshot +def test_dimensions_requiring_join( + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, +) -> None: + """Tests querying 2 dimensions that require a join.""" + dimension_specs = ( + DimensionSpec(element_name="home_state_latest", entity_links=(EntityReference(element_name="user"),)), + DimensionSpec(element_name="is_lux_latest", entity_links=(EntityReference(element_name="listing"),)), + ) + dataflow_plan = dataflow_plan_builder.build_plan_for_distinct_values( + query_spec=MetricFlowQuerySpec(dimension_specs=dimension_specs) + ) + + convert_and_check( + request=request, + mf_test_session_state=mf_test_session_state, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + node=dataflow_plan.sink_output_nodes[0].parent_node, + ) diff --git a/metricflow/test/plan_conversion/test_dataflow_to_sql_plan.py b/metricflow/test/plan_conversion/test_dataflow_to_sql_plan.py index 0c3680a13d..b4eecac5e1 100644 --- a/metricflow/test/plan_conversion/test_dataflow_to_sql_plan.py +++ b/metricflow/test/plan_conversion/test_dataflow_to_sql_plan.py @@ -1068,29 +1068,3 @@ def test_combine_output_node( # noqa: D sql_client=sql_client, node=combine_output_node, ) - - -@pytest.mark.sql_engine_snapshot -def test_dimensions_requiring_join( - request: FixtureRequest, - mf_test_session_state: MetricFlowTestSessionState, - dataflow_plan_builder: DataflowPlanBuilder, - dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, - sql_client: SqlClient, -) -> None: - """Tests querying 2 dimensions that require a join.""" - dimension_specs = ( - DimensionSpec(element_name="home_state_latest", entity_links=(EntityReference(element_name="user"),)), - DimensionSpec(element_name="is_lux_latest", entity_links=(EntityReference(element_name="listing"),)), - ) - dataflow_plan = dataflow_plan_builder.build_plan_for_distinct_values( - query_spec=MetricFlowQuerySpec(dimension_specs=dimension_specs) - ) - - convert_and_check( - request=request, - mf_test_session_state=mf_test_session_state, - dataflow_to_sql_converter=dataflow_to_sql_converter, - sql_client=sql_client, - node=dataflow_plan.sink_output_nodes[0].parent_node, - ) From 952264863a00efe6618fffe52b08e053e4da41cc Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 28 Nov 2023 14:02:48 -0800 Subject: [PATCH 2/7] Update snapshots. --- .../BigQuery/test_dimensions_requiring_join__plan0.sql | 0 .../BigQuery/test_dimensions_requiring_join__plan0_optimized.sql | 0 .../Databricks/test_dimensions_requiring_join__plan0.sql | 0 .../test_dimensions_requiring_join__plan0_optimized.sql | 0 .../SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql | 0 .../DuckDB/test_dimensions_requiring_join__plan0_optimized.sql | 0 .../Postgres/test_dimensions_requiring_join__plan0.sql | 0 .../Postgres/test_dimensions_requiring_join__plan0_optimized.sql | 0 .../Redshift/test_dimensions_requiring_join__plan0.sql | 0 .../Redshift/test_dimensions_requiring_join__plan0_optimized.sql | 0 .../Snowflake/test_dimensions_requiring_join__plan0.sql | 0 .../Snowflake/test_dimensions_requiring_join__plan0_optimized.sql | 0 .../SqlQueryPlan/test_dimensions_requiring_join__plan0.xml | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/BigQuery/test_dimensions_requiring_join__plan0.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/BigQuery/test_dimensions_requiring_join__plan0_optimized.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/Databricks/test_dimensions_requiring_join__plan0.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/Databricks/test_dimensions_requiring_join__plan0_optimized.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/Postgres/test_dimensions_requiring_join__plan0.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/Postgres/test_dimensions_requiring_join__plan0_optimized.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/Redshift/test_dimensions_requiring_join__plan0.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/Redshift/test_dimensions_requiring_join__plan0_optimized.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/Snowflake/test_dimensions_requiring_join__plan0.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/Snowflake/test_dimensions_requiring_join__plan0_optimized.sql (100%) rename metricflow/test/snapshots/{test_dataflow_to_sql_plan.py => test_distinct_values_to_sql.py}/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml (100%) diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimensions_requiring_join__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimensions_requiring_join__plan0.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimensions_requiring_join__plan0.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimensions_requiring_join__plan0.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimensions_requiring_join__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimensions_requiring_join__plan0_optimized.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/BigQuery/test_dimensions_requiring_join__plan0_optimized.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimensions_requiring_join__plan0_optimized.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimensions_requiring_join__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimensions_requiring_join__plan0.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimensions_requiring_join__plan0.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimensions_requiring_join__plan0.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimensions_requiring_join__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimensions_requiring_join__plan0_optimized.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Databricks/test_dimensions_requiring_join__plan0_optimized.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimensions_requiring_join__plan0_optimized.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimensions_requiring_join__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimensions_requiring_join__plan0.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimensions_requiring_join__plan0.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimensions_requiring_join__plan0.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimensions_requiring_join__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimensions_requiring_join__plan0_optimized.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Postgres/test_dimensions_requiring_join__plan0_optimized.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimensions_requiring_join__plan0_optimized.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimensions_requiring_join__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimensions_requiring_join__plan0.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimensions_requiring_join__plan0.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimensions_requiring_join__plan0.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimensions_requiring_join__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimensions_requiring_join__plan0_optimized.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Redshift/test_dimensions_requiring_join__plan0_optimized.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimensions_requiring_join__plan0_optimized.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimensions_requiring_join__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimensions_requiring_join__plan0.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimensions_requiring_join__plan0.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimensions_requiring_join__plan0.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimensions_requiring_join__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimensions_requiring_join__plan0_optimized.sql similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/Snowflake/test_dimensions_requiring_join__plan0_optimized.sql rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimensions_requiring_join__plan0_optimized.sql diff --git a/metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml similarity index 100% rename from metricflow/test/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml rename to metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml From 3675f7144e5cecf4d0da5bb2e8e06493d749ea9f Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 28 Nov 2023 13:18:43 -0800 Subject: [PATCH 3/7] Add test case for distinct values plan with a filter. --- .../test_distinct_values_to_sql.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/metricflow/test/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py b/metricflow/test/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py index 1b365d693d..64b622d380 100644 --- a/metricflow/test/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py +++ b/metricflow/test/plan_conversion/dataflow_to_sql/test_distinct_values_to_sql.py @@ -2,12 +2,15 @@ import pytest from _pytest.fixtures import FixtureRequest +from dbt_semantic_interfaces.implementations.filters.where_filter import PydanticWhereFilter from dbt_semantic_interfaces.references import EntityReference from metricflow.dataflow.builder.dataflow_plan_builder import DataflowPlanBuilder from metricflow.plan_conversion.dataflow_to_sql import DataflowToSqlQueryPlanConverter from metricflow.protocols.sql_client import SqlClient +from metricflow.specs.column_assoc import ColumnAssociationResolver from metricflow.specs.specs import DimensionSpec, MetricFlowQuerySpec +from metricflow.specs.where_filter_transform import WhereSpecFactory from metricflow.test.fixtures.setup_fixtures import MetricFlowTestSessionState from metricflow.test.plan_conversion.test_dataflow_to_sql_plan import convert_and_check @@ -36,3 +39,41 @@ def test_dimensions_requiring_join( sql_client=sql_client, node=dataflow_plan.sink_output_nodes[0].parent_node, ) + + +@pytest.mark.sql_engine_snapshot +def test_dimension_values_with_a_join_and_a_filter( + request: FixtureRequest, + mf_test_session_state: MetricFlowTestSessionState, + column_association_resolver: ColumnAssociationResolver, + dataflow_plan_builder: DataflowPlanBuilder, + dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter, + sql_client: SqlClient, +) -> None: + """Tests querying 2 dimensions that require a join and a filter.""" + dimension_specs = ( + DimensionSpec(element_name="home_state_latest", entity_links=(EntityReference(element_name="user"),)), + DimensionSpec(element_name="is_lux_latest", entity_links=(EntityReference(element_name="listing"),)), + ) + dataflow_plan = dataflow_plan_builder.build_plan_for_distinct_values( + query_spec=MetricFlowQuerySpec( + dimension_specs=dimension_specs, + where_constraint=( + WhereSpecFactory( + column_association_resolver=column_association_resolver, + ).create_from_where_filter( + PydanticWhereFilter( + where_sql_template="{{ Dimension('user__home_state_latest') }} = 'us'", + ) + ) + ), + ) + ) + + convert_and_check( + request=request, + mf_test_session_state=mf_test_session_state, + dataflow_to_sql_converter=dataflow_to_sql_converter, + sql_client=sql_client, + node=dataflow_plan.sink_output_nodes[0].parent_node, + ) From 5c2e0e871e717a60056b42e1e3bc1d4d3993e006 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 28 Nov 2023 14:10:02 -0800 Subject: [PATCH 4/7] Add snapshots for test_dimension_values_with_a_join_and_a_filter. --- ...values_with_a_join_and_a_filter__plan0.sql | 231 +++++ ...h_a_join_and_a_filter__plan0_optimized.sql | 21 + ...values_with_a_join_and_a_filter__plan0.sql | 231 +++++ ...h_a_join_and_a_filter__plan0_optimized.sql | 21 + ...values_with_a_join_and_a_filter__plan0.sql | 231 +++++ ...h_a_join_and_a_filter__plan0_optimized.sql | 21 + ...values_with_a_join_and_a_filter__plan0.sql | 231 +++++ ...h_a_join_and_a_filter__plan0_optimized.sql | 21 + ...values_with_a_join_and_a_filter__plan0.sql | 231 +++++ ...h_a_join_and_a_filter__plan0_optimized.sql | 21 + ...values_with_a_join_and_a_filter__plan0.sql | 231 +++++ ...h_a_join_and_a_filter__plan0_optimized.sql | 21 + ...values_with_a_join_and_a_filter__plan0.xml | 869 ++++++++++++++++++ 13 files changed, 2381 insertions(+) create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql create mode 100644 metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimension_values_with_a_join_and_a_filter__plan0.xml diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql new file mode 100644 index 0000000000..f8bd4f1ee4 --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -0,0 +1,231 @@ +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest +FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.home_state_latest AS user__home_state_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Join Standard Outputs + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_2.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC(listings_latest_src_10004.created_at, day) AS ds__day + , DATE_TRUNC(listings_latest_src_10004.created_at, isoweek) AS ds__week + , DATE_TRUNC(listings_latest_src_10004.created_at, month) AS ds__month + , DATE_TRUNC(listings_latest_src_10004.created_at, quarter) AS ds__quarter + , DATE_TRUNC(listings_latest_src_10004.created_at, year) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_10004.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_10004.created_at) - 1) AS ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC(listings_latest_src_10004.created_at, day) AS created_at__day + , DATE_TRUNC(listings_latest_src_10004.created_at, isoweek) AS created_at__week + , DATE_TRUNC(listings_latest_src_10004.created_at, month) AS created_at__month + , DATE_TRUNC(listings_latest_src_10004.created_at, quarter) AS created_at__quarter + , DATE_TRUNC(listings_latest_src_10004.created_at, year) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_10004.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_10004.created_at) - 1) AS created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC(listings_latest_src_10004.created_at, day) AS listing__ds__day + , DATE_TRUNC(listings_latest_src_10004.created_at, isoweek) AS listing__ds__week + , DATE_TRUNC(listings_latest_src_10004.created_at, month) AS listing__ds__month + , DATE_TRUNC(listings_latest_src_10004.created_at, quarter) AS listing__ds__quarter + , DATE_TRUNC(listings_latest_src_10004.created_at, year) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_10004.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_10004.created_at) - 1) AS listing__ds__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC(listings_latest_src_10004.created_at, day) AS listing__created_at__day + , DATE_TRUNC(listings_latest_src_10004.created_at, isoweek) AS listing__created_at__week + , DATE_TRUNC(listings_latest_src_10004.created_at, month) AS listing__created_at__month + , DATE_TRUNC(listings_latest_src_10004.created_at, quarter) AS listing__created_at__quarter + , DATE_TRUNC(listings_latest_src_10004.created_at, year) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , IF(EXTRACT(dayofweek FROM listings_latest_src_10004.created_at) = 1, 7, EXTRACT(dayofweek FROM listings_latest_src_10004.created_at) - 1) AS listing__created_at__extract_dow + , EXTRACT(dayofyear FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_0 + FULL OUTER JOIN ( + -- Pass Only Elements: + -- ['home_state_latest', 'user'] + SELECT + subq_1.user + , subq_1.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC(users_latest_src_10008.ds, day) AS ds_latest__day + , DATE_TRUNC(users_latest_src_10008.ds, isoweek) AS ds_latest__week + , DATE_TRUNC(users_latest_src_10008.ds, month) AS ds_latest__month + , DATE_TRUNC(users_latest_src_10008.ds, quarter) AS ds_latest__quarter + , DATE_TRUNC(users_latest_src_10008.ds, year) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_10008.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_10008.ds) - 1) AS ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_10008.ds) AS ds_latest__extract_doy + , users_latest_src_10008.home_state_latest + , DATE_TRUNC(users_latest_src_10008.ds, day) AS user__ds_latest__day + , DATE_TRUNC(users_latest_src_10008.ds, isoweek) AS user__ds_latest__week + , DATE_TRUNC(users_latest_src_10008.ds, month) AS user__ds_latest__month + , DATE_TRUNC(users_latest_src_10008.ds, quarter) AS user__ds_latest__quarter + , DATE_TRUNC(users_latest_src_10008.ds, year) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day + , IF(EXTRACT(dayofweek FROM users_latest_src_10008.ds) = 1, 7, EXTRACT(dayofweek FROM users_latest_src_10008.ds) - 1) AS user__ds_latest__extract_dow + , EXTRACT(dayofyear FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy + , users_latest_src_10008.home_state_latest AS user__home_state_latest + , users_latest_src_10008.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10008 + ) subq_1 + ) subq_2 + ON + subq_0.user = subq_2.user + ) subq_3 + WHERE user__home_state_latest = 'us' +) subq_4 +GROUP BY + listing__is_lux_latest + , user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql new file mode 100644 index 0000000000..1b13fa4380 --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -0,0 +1,21 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + listing__is_lux_latest + , home_state_latest AS user__home_state_latest +FROM ( + -- Join Standard Outputs + SELECT + listings_latest_src_10004.is_lux AS listing__is_lux_latest + , users_latest_src_10008.home_state_latest AS user__home_state_latest + FROM ***************************.dim_listings_latest listings_latest_src_10004 + FULL OUTER JOIN + ***************************.dim_users_latest users_latest_src_10008 + ON + listings_latest_src_10004.user_id = users_latest_src_10008.user_id +) subq_8 +WHERE user__home_state_latest = 'us' +GROUP BY + listing__is_lux_latest + , user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql new file mode 100644 index 0000000000..a5bda36a3d --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -0,0 +1,231 @@ +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest +FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.home_state_latest AS user__home_state_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Join Standard Outputs + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_2.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_0 + FULL OUTER JOIN ( + -- Pass Only Elements: + -- ['home_state_latest', 'user'] + SELECT + subq_1.user + , subq_1.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_10008.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_10008.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy + , users_latest_src_10008.home_state_latest + , DATE_TRUNC('day', users_latest_src_10008.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day + , EXTRACT(DAYOFWEEK_ISO FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy + , users_latest_src_10008.home_state_latest AS user__home_state_latest + , users_latest_src_10008.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10008 + ) subq_1 + ) subq_2 + ON + subq_0.user = subq_2.user + ) subq_3 + WHERE user__home_state_latest = 'us' +) subq_4 +GROUP BY + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql new file mode 100644 index 0000000000..365011984d --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -0,0 +1,21 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + listing__is_lux_latest + , home_state_latest AS user__home_state_latest +FROM ( + -- Join Standard Outputs + SELECT + listings_latest_src_10004.is_lux AS listing__is_lux_latest + , users_latest_src_10008.home_state_latest AS user__home_state_latest + FROM ***************************.dim_listings_latest listings_latest_src_10004 + FULL OUTER JOIN + ***************************.dim_users_latest users_latest_src_10008 + ON + listings_latest_src_10004.user_id = users_latest_src_10008.user_id +) subq_8 +WHERE user__home_state_latest = 'us' +GROUP BY + listing__is_lux_latest + , home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql new file mode 100644 index 0000000000..b5f7a286e3 --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -0,0 +1,231 @@ +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest +FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.home_state_latest AS user__home_state_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Join Standard Outputs + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_2.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_0 + FULL OUTER JOIN ( + -- Pass Only Elements: + -- ['home_state_latest', 'user'] + SELECT + subq_1.user + , subq_1.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_10008.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_10008.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy + , users_latest_src_10008.home_state_latest + , DATE_TRUNC('day', users_latest_src_10008.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy + , users_latest_src_10008.home_state_latest AS user__home_state_latest + , users_latest_src_10008.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10008 + ) subq_1 + ) subq_2 + ON + subq_0.user = subq_2.user + ) subq_3 + WHERE user__home_state_latest = 'us' +) subq_4 +GROUP BY + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql new file mode 100644 index 0000000000..365011984d --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -0,0 +1,21 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + listing__is_lux_latest + , home_state_latest AS user__home_state_latest +FROM ( + -- Join Standard Outputs + SELECT + listings_latest_src_10004.is_lux AS listing__is_lux_latest + , users_latest_src_10008.home_state_latest AS user__home_state_latest + FROM ***************************.dim_listings_latest listings_latest_src_10004 + FULL OUTER JOIN + ***************************.dim_users_latest users_latest_src_10008 + ON + listings_latest_src_10004.user_id = users_latest_src_10008.user_id +) subq_8 +WHERE user__home_state_latest = 'us' +GROUP BY + listing__is_lux_latest + , home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql new file mode 100644 index 0000000000..b5f7a286e3 --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -0,0 +1,231 @@ +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest +FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.home_state_latest AS user__home_state_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Join Standard Outputs + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_2.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_0 + FULL OUTER JOIN ( + -- Pass Only Elements: + -- ['home_state_latest', 'user'] + SELECT + subq_1.user + , subq_1.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_10008.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_10008.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy + , users_latest_src_10008.home_state_latest + , DATE_TRUNC('day', users_latest_src_10008.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day + , EXTRACT(isodow FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy + , users_latest_src_10008.home_state_latest AS user__home_state_latest + , users_latest_src_10008.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10008 + ) subq_1 + ) subq_2 + ON + subq_0.user = subq_2.user + ) subq_3 + WHERE user__home_state_latest = 'us' +) subq_4 +GROUP BY + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql new file mode 100644 index 0000000000..365011984d --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -0,0 +1,21 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + listing__is_lux_latest + , home_state_latest AS user__home_state_latest +FROM ( + -- Join Standard Outputs + SELECT + listings_latest_src_10004.is_lux AS listing__is_lux_latest + , users_latest_src_10008.home_state_latest AS user__home_state_latest + FROM ***************************.dim_listings_latest listings_latest_src_10004 + FULL OUTER JOIN + ***************************.dim_users_latest users_latest_src_10008 + ON + listings_latest_src_10004.user_id = users_latest_src_10008.user_id +) subq_8 +WHERE user__home_state_latest = 'us' +GROUP BY + listing__is_lux_latest + , home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql new file mode 100644 index 0000000000..de8d5e0070 --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -0,0 +1,231 @@ +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest +FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.home_state_latest AS user__home_state_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Join Standard Outputs + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_2.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_10004.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_10004.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_10004.created_at) END AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_10004.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_10004.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_10004.created_at) END AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_10004.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_10004.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_10004.created_at) END AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , CASE WHEN EXTRACT(dow FROM listings_latest_src_10004.created_at) = 0 THEN EXTRACT(dow FROM listings_latest_src_10004.created_at) + 7 ELSE EXTRACT(dow FROM listings_latest_src_10004.created_at) END AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_0 + FULL OUTER JOIN ( + -- Pass Only Elements: + -- ['home_state_latest', 'user'] + SELECT + subq_1.user + , subq_1.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_10008.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_10008.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_10008.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_10008.ds) END AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy + , users_latest_src_10008.home_state_latest + , DATE_TRUNC('day', users_latest_src_10008.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day + , CASE WHEN EXTRACT(dow FROM users_latest_src_10008.ds) = 0 THEN EXTRACT(dow FROM users_latest_src_10008.ds) + 7 ELSE EXTRACT(dow FROM users_latest_src_10008.ds) END AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy + , users_latest_src_10008.home_state_latest AS user__home_state_latest + , users_latest_src_10008.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10008 + ) subq_1 + ) subq_2 + ON + subq_0.user = subq_2.user + ) subq_3 + WHERE user__home_state_latest = 'us' +) subq_4 +GROUP BY + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql new file mode 100644 index 0000000000..365011984d --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -0,0 +1,21 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + listing__is_lux_latest + , home_state_latest AS user__home_state_latest +FROM ( + -- Join Standard Outputs + SELECT + listings_latest_src_10004.is_lux AS listing__is_lux_latest + , users_latest_src_10008.home_state_latest AS user__home_state_latest + FROM ***************************.dim_listings_latest listings_latest_src_10004 + FULL OUTER JOIN + ***************************.dim_users_latest users_latest_src_10008 + ON + listings_latest_src_10004.user_id = users_latest_src_10008.user_id +) subq_8 +WHERE user__home_state_latest = 'us' +GROUP BY + listing__is_lux_latest + , home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql new file mode 100644 index 0000000000..ae2b676c77 --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -0,0 +1,231 @@ +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest +FROM ( + -- Constrain Output with WHERE + SELECT + subq_3.ds__day + , subq_3.ds__week + , subq_3.ds__month + , subq_3.ds__quarter + , subq_3.ds__year + , subq_3.ds__extract_year + , subq_3.ds__extract_quarter + , subq_3.ds__extract_month + , subq_3.ds__extract_day + , subq_3.ds__extract_dow + , subq_3.ds__extract_doy + , subq_3.created_at__day + , subq_3.created_at__week + , subq_3.created_at__month + , subq_3.created_at__quarter + , subq_3.created_at__year + , subq_3.created_at__extract_year + , subq_3.created_at__extract_quarter + , subq_3.created_at__extract_month + , subq_3.created_at__extract_day + , subq_3.created_at__extract_dow + , subq_3.created_at__extract_doy + , subq_3.listing__ds__day + , subq_3.listing__ds__week + , subq_3.listing__ds__month + , subq_3.listing__ds__quarter + , subq_3.listing__ds__year + , subq_3.listing__ds__extract_year + , subq_3.listing__ds__extract_quarter + , subq_3.listing__ds__extract_month + , subq_3.listing__ds__extract_day + , subq_3.listing__ds__extract_dow + , subq_3.listing__ds__extract_doy + , subq_3.listing__created_at__day + , subq_3.listing__created_at__week + , subq_3.listing__created_at__month + , subq_3.listing__created_at__quarter + , subq_3.listing__created_at__year + , subq_3.listing__created_at__extract_year + , subq_3.listing__created_at__extract_quarter + , subq_3.listing__created_at__extract_month + , subq_3.listing__created_at__extract_day + , subq_3.listing__created_at__extract_dow + , subq_3.listing__created_at__extract_doy + , subq_3.listing + , subq_3.user + , subq_3.listing__user + , subq_3.country_latest + , subq_3.is_lux_latest + , subq_3.capacity_latest + , subq_3.listing__country_latest + , subq_3.listing__is_lux_latest + , subq_3.listing__capacity_latest + , subq_3.home_state_latest AS user__home_state_latest + , subq_3.listings + , subq_3.largest_listing + , subq_3.smallest_listing + FROM ( + -- Join Standard Outputs + SELECT + subq_0.ds__day AS ds__day + , subq_0.ds__week AS ds__week + , subq_0.ds__month AS ds__month + , subq_0.ds__quarter AS ds__quarter + , subq_0.ds__year AS ds__year + , subq_0.ds__extract_year AS ds__extract_year + , subq_0.ds__extract_quarter AS ds__extract_quarter + , subq_0.ds__extract_month AS ds__extract_month + , subq_0.ds__extract_day AS ds__extract_day + , subq_0.ds__extract_dow AS ds__extract_dow + , subq_0.ds__extract_doy AS ds__extract_doy + , subq_0.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_2.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_10004.capacity AS largest_listing + , listings_latest_src_10004.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_10004.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_10004.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS created_at__extract_doy + , listings_latest_src_10004.country AS country_latest + , listings_latest_src_10004.is_lux AS is_lux_latest + , listings_latest_src_10004.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__ds__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_10004.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_10004.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_10004.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_10004.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_10004.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_10004.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_day + , EXTRACT(dayofweekiso FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_10004.created_at) AS listing__created_at__extract_doy + , listings_latest_src_10004.country AS listing__country_latest + , listings_latest_src_10004.is_lux AS listing__is_lux_latest + , listings_latest_src_10004.capacity AS listing__capacity_latest + , listings_latest_src_10004.listing_id AS listing + , listings_latest_src_10004.user_id AS user + , listings_latest_src_10004.user_id AS listing__user + FROM ***************************.dim_listings_latest listings_latest_src_10004 + ) subq_0 + FULL OUTER JOIN ( + -- Pass Only Elements: + -- ['home_state_latest', 'user'] + SELECT + subq_1.user + , subq_1.home_state_latest + FROM ( + -- Read Elements From Semantic Model 'users_latest' + SELECT + DATE_TRUNC('day', users_latest_src_10008.ds) AS ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_10008.ds) AS ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS ds_latest__extract_doy + , users_latest_src_10008.home_state_latest + , DATE_TRUNC('day', users_latest_src_10008.ds) AS user__ds_latest__day + , DATE_TRUNC('week', users_latest_src_10008.ds) AS user__ds_latest__week + , DATE_TRUNC('month', users_latest_src_10008.ds) AS user__ds_latest__month + , DATE_TRUNC('quarter', users_latest_src_10008.ds) AS user__ds_latest__quarter + , DATE_TRUNC('year', users_latest_src_10008.ds) AS user__ds_latest__year + , EXTRACT(year FROM users_latest_src_10008.ds) AS user__ds_latest__extract_year + , EXTRACT(quarter FROM users_latest_src_10008.ds) AS user__ds_latest__extract_quarter + , EXTRACT(month FROM users_latest_src_10008.ds) AS user__ds_latest__extract_month + , EXTRACT(day FROM users_latest_src_10008.ds) AS user__ds_latest__extract_day + , EXTRACT(dayofweekiso FROM users_latest_src_10008.ds) AS user__ds_latest__extract_dow + , EXTRACT(doy FROM users_latest_src_10008.ds) AS user__ds_latest__extract_doy + , users_latest_src_10008.home_state_latest AS user__home_state_latest + , users_latest_src_10008.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_10008 + ) subq_1 + ) subq_2 + ON + subq_0.user = subq_2.user + ) subq_3 + WHERE user__home_state_latest = 'us' +) subq_4 +GROUP BY + subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql new file mode 100644 index 0000000000..365011984d --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -0,0 +1,21 @@ +-- Constrain Output with WHERE +-- Pass Only Elements: +-- ['user__home_state_latest', 'listing__is_lux_latest'] +SELECT + listing__is_lux_latest + , home_state_latest AS user__home_state_latest +FROM ( + -- Join Standard Outputs + SELECT + listings_latest_src_10004.is_lux AS listing__is_lux_latest + , users_latest_src_10008.home_state_latest AS user__home_state_latest + FROM ***************************.dim_listings_latest listings_latest_src_10004 + FULL OUTER JOIN + ***************************.dim_users_latest users_latest_src_10008 + ON + listings_latest_src_10004.user_id = users_latest_src_10008.user_id +) subq_8 +WHERE user__home_state_latest = 'us' +GROUP BY + listing__is_lux_latest + , home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimension_values_with_a_join_and_a_filter__plan0.xml b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimension_values_with_a_join_and_a_filter__plan0.xml new file mode 100644 index 0000000000..26d712d0f6 --- /dev/null +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimension_values_with_a_join_and_a_filter__plan0.xml @@ -0,0 +1,869 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 0619e290b60be0e330a21a6830ce2d3965aca962 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 28 Nov 2023 13:10:03 -0800 Subject: [PATCH 5/7] Add a fix to resolve incorrect column names in the output of WhereConstraintNode. --- metricflow/plan_conversion/dataflow_to_sql.py | 10 +++++-- .../plan_conversion/instance_converters.py | 29 ++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index 3893551625..f47242e48e 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -755,8 +755,12 @@ def visit_pass_elements_filter_node(self, node: FilterElementsNode) -> SqlDataSe def visit_where_constraint_node(self, node: WhereConstraintNode) -> SqlDataSet: """Adds where clause to SQL statement from parent node.""" - from_data_set: SqlDataSet = node.parent_node.accept(self) - output_instance_set = from_data_set.instance_set + parent_data_set: SqlDataSet = node.parent_node.accept(self) + # Since we're copying the instance set from the parent to conveniently generate the output instance set for this + # node, we'll need to change the column names. + output_instance_set = parent_data_set.instance_set.transform( + ChangeAssociatedColumns(self._column_association_resolver) + ) from_data_set_alias = self._next_unique_table_alias() column_associations_in_where_sql: Sequence[ColumnAssociation] = CreateColumnAssociations( @@ -771,7 +775,7 @@ def visit_where_constraint_node(self, node: WhereConstraintNode) -> SqlDataSet: select_columns=output_instance_set.transform( CreateSelectColumnsForInstances(from_data_set_alias, self._column_association_resolver) ).as_tuple(), - from_source=from_data_set.sql_select_node, + from_source=parent_data_set.sql_select_node, from_source_alias=from_data_set_alias, joins_descs=(), group_bys=(), diff --git a/metricflow/plan_conversion/instance_converters.py b/metricflow/plan_conversion/instance_converters.py index 598675f4dd..d56e1e8473 100644 --- a/metricflow/plan_conversion/instance_converters.py +++ b/metricflow/plan_conversion/instance_converters.py @@ -845,7 +845,34 @@ def transform(self, instance_set: InstanceSet) -> SelectColumnSet: # noqa: D class ChangeAssociatedColumns(InstanceSetTransform[InstanceSet]): - """Change the columns associated with instances to the one specified by the resolver.""" + """Change the columns associated with instances to the one specified by the resolver. + + This is useful for conveniently generating output instances for a node that serve as a "pass-through". The output + instances can be a copy of the parent's instances, except that the column names need to be changed. + + e.g. the parent may have a data set: + sql: + SELECT + is_lux AS is_lux_latext + ... + instance: + DimensionInstance(column_name="is_lux", ...) + + but for the current node, we want a data set like: + + sql: + SELECT + is_lux_latest + ... + FROM ( + -- SQL from parent + is_lux AS is_lux_latest + ... + ) + ... + instance: + DimensionInstance(column_name="is_lux_latest") + """ def __init__(self, column_association_resolver: ColumnAssociationResolver) -> None: # noqa: D self._column_association_resolver = column_association_resolver From f5d77ecf13dda6744802dcc125280746d10f7068 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 28 Nov 2023 14:12:39 -0800 Subject: [PATCH 6/7] Update snapshots after fixing column name rendering. --- .../test_dimension_values_with_a_join_and_a_filter__plan0.sql | 2 +- ...nsion_values_with_a_join_and_a_filter__plan0_optimized.sql | 2 +- .../test_dimension_values_with_a_join_and_a_filter__plan0.sql | 2 +- ...nsion_values_with_a_join_and_a_filter__plan0_optimized.sql | 4 ++-- .../test_dimension_values_with_a_join_and_a_filter__plan0.sql | 2 +- ...nsion_values_with_a_join_and_a_filter__plan0_optimized.sql | 4 ++-- .../test_dimension_values_with_a_join_and_a_filter__plan0.sql | 2 +- ...nsion_values_with_a_join_and_a_filter__plan0_optimized.sql | 4 ++-- .../test_dimension_values_with_a_join_and_a_filter__plan0.sql | 2 +- ...nsion_values_with_a_join_and_a_filter__plan0_optimized.sql | 4 ++-- .../test_dimension_values_with_a_join_and_a_filter__plan0.sql | 2 +- ...nsion_values_with_a_join_and_a_filter__plan0_optimized.sql | 4 ++-- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql index f8bd4f1ee4..e789be29d6 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -59,7 +59,7 @@ FROM ( , subq_3.listing__country_latest , subq_3.listing__is_lux_latest , subq_3.listing__capacity_latest - , subq_3.home_state_latest AS user__home_state_latest + , subq_3.user__home_state_latest , subq_3.listings , subq_3.largest_listing , subq_3.smallest_listing diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index 1b13fa4380..3d0526ebb2 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/BigQuery/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -3,7 +3,7 @@ -- ['user__home_state_latest', 'listing__is_lux_latest'] SELECT listing__is_lux_latest - , home_state_latest AS user__home_state_latest + , user__home_state_latest FROM ( -- Join Standard Outputs SELECT diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql index a5bda36a3d..68cefdd899 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -59,7 +59,7 @@ FROM ( , subq_3.listing__country_latest , subq_3.listing__is_lux_latest , subq_3.listing__capacity_latest - , subq_3.home_state_latest AS user__home_state_latest + , subq_3.user__home_state_latest , subq_3.listings , subq_3.largest_listing , subq_3.smallest_listing diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index 365011984d..3d0526ebb2 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Databricks/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -3,7 +3,7 @@ -- ['user__home_state_latest', 'listing__is_lux_latest'] SELECT listing__is_lux_latest - , home_state_latest AS user__home_state_latest + , user__home_state_latest FROM ( -- Join Standard Outputs SELECT @@ -18,4 +18,4 @@ FROM ( WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest - , home_state_latest + , user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql index b5f7a286e3..09d4611a5c 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -59,7 +59,7 @@ FROM ( , subq_3.listing__country_latest , subq_3.listing__is_lux_latest , subq_3.listing__capacity_latest - , subq_3.home_state_latest AS user__home_state_latest + , subq_3.user__home_state_latest , subq_3.listings , subq_3.largest_listing , subq_3.smallest_listing diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index 365011984d..3d0526ebb2 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -3,7 +3,7 @@ -- ['user__home_state_latest', 'listing__is_lux_latest'] SELECT listing__is_lux_latest - , home_state_latest AS user__home_state_latest + , user__home_state_latest FROM ( -- Join Standard Outputs SELECT @@ -18,4 +18,4 @@ FROM ( WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest - , home_state_latest + , user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql index b5f7a286e3..09d4611a5c 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -59,7 +59,7 @@ FROM ( , subq_3.listing__country_latest , subq_3.listing__is_lux_latest , subq_3.listing__capacity_latest - , subq_3.home_state_latest AS user__home_state_latest + , subq_3.user__home_state_latest , subq_3.listings , subq_3.largest_listing , subq_3.smallest_listing diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index 365011984d..3d0526ebb2 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Postgres/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -3,7 +3,7 @@ -- ['user__home_state_latest', 'listing__is_lux_latest'] SELECT listing__is_lux_latest - , home_state_latest AS user__home_state_latest + , user__home_state_latest FROM ( -- Join Standard Outputs SELECT @@ -18,4 +18,4 @@ FROM ( WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest - , home_state_latest + , user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql index de8d5e0070..7c513423a1 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -59,7 +59,7 @@ FROM ( , subq_3.listing__country_latest , subq_3.listing__is_lux_latest , subq_3.listing__capacity_latest - , subq_3.home_state_latest AS user__home_state_latest + , subq_3.user__home_state_latest , subq_3.listings , subq_3.largest_listing , subq_3.smallest_listing diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index 365011984d..3d0526ebb2 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Redshift/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -3,7 +3,7 @@ -- ['user__home_state_latest', 'listing__is_lux_latest'] SELECT listing__is_lux_latest - , home_state_latest AS user__home_state_latest + , user__home_state_latest FROM ( -- Join Standard Outputs SELECT @@ -18,4 +18,4 @@ FROM ( WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest - , home_state_latest + , user__home_state_latest diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql index ae2b676c77..fd366a79c8 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -59,7 +59,7 @@ FROM ( , subq_3.listing__country_latest , subq_3.listing__is_lux_latest , subq_3.listing__capacity_latest - , subq_3.home_state_latest AS user__home_state_latest + , subq_3.user__home_state_latest , subq_3.listings , subq_3.largest_listing , subq_3.smallest_listing diff --git a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index 365011984d..3d0526ebb2 100644 --- a/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/metricflow/test/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/Snowflake/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -3,7 +3,7 @@ -- ['user__home_state_latest', 'listing__is_lux_latest'] SELECT listing__is_lux_latest - , home_state_latest AS user__home_state_latest + , user__home_state_latest FROM ( -- Join Standard Outputs SELECT @@ -18,4 +18,4 @@ FROM ( WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest - , home_state_latest + , user__home_state_latest From bc60c7e9c1de3ee6ac7f47e9dbe095a5f02805ac Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 28 Nov 2023 14:23:26 -0800 Subject: [PATCH 7/7] Add change log for #908. --- .changes/unreleased/Fixes-20231128-142315.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20231128-142315.yaml diff --git a/.changes/unreleased/Fixes-20231128-142315.yaml b/.changes/unreleased/Fixes-20231128-142315.yaml new file mode 100644 index 0000000000..af60703bee --- /dev/null +++ b/.changes/unreleased/Fixes-20231128-142315.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix Incorrect SQL Column Name Rendering for WhereConstraintNode +time: 2023-11-28T14:23:15.269611-08:00 +custom: + Author: plypaul + Issue: "908"