Skip to content

Commit

Permalink
Add test case to check semantic models between dataflow and parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed May 11, 2024
1 parent 546adbf commit 1cab5c8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tests_metricflow/integration/test_configured_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration
from metricflow_semantics.test_helpers.time_helpers import ConfigurableTimeSource

from metricflow.engine.metricflow_engine import MetricFlowEngine, MetricFlowQueryRequest
from metricflow.engine.metricflow_engine import MetricFlowEngine, MetricFlowQueryRequest, MetricFlowQueryResult
from metricflow.plan_conversion.time_spine import TimeSpineSource
from metricflow.protocols.sql_client import SqlClient
from metricflow.sql.sql_exprs import (
Expand All @@ -37,6 +37,7 @@
SqlSubtractTimeIntervalExpression,
)
from tests_metricflow.compare_df import assert_dataframes_equal
from tests_metricflow.dataflow.optimizer.source_scan.test_source_scan_optimizer import DataflowPlanLookup
from tests_metricflow.integration.configured_test_case import (
CONFIGURED_INTEGRATION_TESTS_REPOSITORY,
IntegrationTestModel,
Expand Down Expand Up @@ -294,7 +295,7 @@ def test_case(
group_by.append(TimeDimensionParameter(**kwargs))
else:
group_by.append(DimensionOrEntityParameter(**kwargs))
query_result = engine.query(
query_result: MetricFlowQueryResult = engine.query(
MetricFlowQueryRequest.create_with_random_request_id(
metric_names=case.metrics,
group_by_names=case.group_bys if len(case.group_bys) > 0 else None,
Expand Down Expand Up @@ -361,3 +362,16 @@ def test_case(
)
# If we sort, it's effectively not checking the order whatever order that the output was would be overwritten.
assert_dataframes_equal(actual, expected, sort_columns=not case.check_order, allow_empty=case.allow_empty)

# Check that the parse result and the dataflow plan show the same semantic models read.
if name in {"itest_dimensions.yaml/distinct_values_query_with_metric_filter"}:
pytest.skip(
"Skipping the congruence check for semantic models queried by the parser vs. the dataflow as "
"metrics-in-filters is a WIP."
)
parse_query_result = query_result.explain_result.parse_query_result

dataflow_plan_lookup = DataflowPlanLookup(query_result.dataflow_plan)
dataflow_queried_semantic_models = dataflow_plan_lookup.read_semantic_models()

assert tuple(parse_query_result.queried_semantic_models) == tuple(dataflow_queried_semantic_models)

0 comments on commit 1cab5c8

Please sign in to comment.