Skip to content

Commit e49bbce

Browse files
committed
Add test for optimization.
1 parent 98e62f4 commit e49bbce

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests_metricflow/integration/test_mf_engine.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from _pytest.fixtures import FixtureRequest
44
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration
55

6+
from metricflow.engine.metricflow_engine import MetricFlowExplainResult, MetricFlowQueryRequest
7+
from metricflow.sql.optimizer.optimization_levels import SqlQueryOptimizationLevel
68
from tests_metricflow.integration.conftest import IntegrationTestHelpers
79
from tests_metricflow.snapshot_utils import assert_object_snapshot_equal
810

@@ -16,3 +18,26 @@ def test_list_dimensions( # noqa: D103
1618
obj_id="result0",
1719
obj=sorted([dim.qualified_name for dim in it_helpers.mf_engine.list_dimensions()]),
1820
)
21+
22+
23+
def test_sql_optimization_level(it_helpers: IntegrationTestHelpers) -> None:
24+
"""Check that different SQL optimization levels produce different SQL."""
25+
assert (
26+
SqlQueryOptimizationLevel.default_level() != SqlQueryOptimizationLevel.O0
27+
), "The default optimization level should be different from the lowest level."
28+
explain_result_at_default_level: MetricFlowExplainResult = it_helpers.mf_engine.explain(
29+
MetricFlowQueryRequest.create_with_random_request_id(
30+
metric_names=("bookings",),
31+
group_by_names=("metric_time",),
32+
sql_optimization_level=SqlQueryOptimizationLevel.default_level(),
33+
)
34+
)
35+
explain_result_at_level_0: MetricFlowExplainResult = it_helpers.mf_engine.explain(
36+
MetricFlowQueryRequest.create_with_random_request_id(
37+
metric_names=("bookings",),
38+
group_by_names=("metric_time",),
39+
sql_optimization_level=SqlQueryOptimizationLevel.O0,
40+
)
41+
)
42+
43+
assert explain_result_at_default_level.rendered_sql.sql_query != explain_result_at_level_0.rendered_sql.sql_query

0 commit comments

Comments
 (0)