Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for metric filters with inner-query joins #1208

Merged
merged 8 commits into from
May 17, 2024
7 changes: 7 additions & 0 deletions tests_metricflow/fixtures/dataflow_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ def multihop_dataflow_plan_builder( # noqa: D103
].dataflow_plan_builder


@pytest.fixture(scope="session")
def multihop_query_parser( # noqa: D103
mf_engine_test_fixture_mapping: Mapping[SemanticManifestSetup, MetricFlowEngineTestFixture]
) -> MetricFlowQueryParser:
return mf_engine_test_fixture_mapping[SemanticManifestSetup.PARTITIONED_MULTI_HOP_JOIN_MANIFEST].query_parser


@pytest.fixture(scope="session")
def scd_column_association_resolver( # noqa: D103
mf_engine_test_fixture_mapping: Mapping[SemanticManifestSetup, MetricFlowEngineTestFixture]
Expand Down
54 changes: 54 additions & 0 deletions tests_metricflow/query_rendering/test_metric_filter_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,57 @@ def test_filter_with_conversion_metric( # noqa: D103
sql_client=sql_client,
node=dataflow_plan.sink_output_nodes[0].parent_node,
)


@pytest.mark.sql_engine_snapshot
def test_inner_query_single_hop(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
multihop_dataflow_plan_builder: DataflowPlanBuilder,
sql_client: SqlClient,
multihop_dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
multihop_query_parser: MetricFlowQueryParser,
) -> None:
"""Tests rendering for a metric filter using a one-hop join in the inner query."""
query_spec = multihop_query_parser.parse_and_validate_query(
metric_names=("third_hop_count",),
where_constraint=PydanticWhereFilter(
where_sql_template="{{ Metric('paraguayan_customers', ['customer_id__customer_third_hop_id']) }} > 0",
),
)
dataflow_plan = multihop_dataflow_plan_builder.build_plan(query_spec)

convert_and_check(
request=request,
mf_test_configuration=mf_test_configuration,
dataflow_to_sql_converter=multihop_dataflow_to_sql_converter,
sql_client=sql_client,
node=dataflow_plan.sink_output_nodes[0].parent_node,
)


@pytest.mark.sql_engine_snapshot
def test_inner_query_multi_hop(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
multihop_dataflow_plan_builder: DataflowPlanBuilder,
sql_client: SqlClient,
multihop_dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
multihop_query_parser: MetricFlowQueryParser,
) -> None:
"""Tests rendering for a metric filter using a two-hop join in the inner query."""
query_spec = multihop_query_parser.parse_and_validate_query(
metric_names=("third_hop_count",),
where_constraint=PydanticWhereFilter(
where_sql_template="{{ Metric('txn_count', ['account_id__customer_id__customer_third_hop_id']) }} > 2",
),
Comment on lines +348 to +352
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

)
dataflow_plan = multihop_dataflow_plan_builder.build_plan(query_spec)

convert_and_check(
request=request,
mf_test_configuration=mf_test_configuration,
dataflow_to_sql_converter=multihop_dataflow_to_sql_converter,
sql_client=sql_client,
node=dataflow_plan.sink_output_nodes[0].parent_node,
)
Loading