Skip to content

Commit

Permalink
Add test for optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Nov 13, 2024
1 parent 98e62f4 commit e49bbce
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests_metricflow/integration/test_mf_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from _pytest.fixtures import FixtureRequest
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration

from metricflow.engine.metricflow_engine import MetricFlowExplainResult, MetricFlowQueryRequest
from metricflow.sql.optimizer.optimization_levels import SqlQueryOptimizationLevel
from tests_metricflow.integration.conftest import IntegrationTestHelpers
from tests_metricflow.snapshot_utils import assert_object_snapshot_equal

Expand All @@ -16,3 +18,26 @@ def test_list_dimensions( # noqa: D103
obj_id="result0",
obj=sorted([dim.qualified_name for dim in it_helpers.mf_engine.list_dimensions()]),
)


def test_sql_optimization_level(it_helpers: IntegrationTestHelpers) -> None:
"""Check that different SQL optimization levels produce different SQL."""
assert (
SqlQueryOptimizationLevel.default_level() != SqlQueryOptimizationLevel.O0
), "The default optimization level should be different from the lowest level."
explain_result_at_default_level: MetricFlowExplainResult = it_helpers.mf_engine.explain(
MetricFlowQueryRequest.create_with_random_request_id(
metric_names=("bookings",),
group_by_names=("metric_time",),
sql_optimization_level=SqlQueryOptimizationLevel.default_level(),
)
)
explain_result_at_level_0: MetricFlowExplainResult = it_helpers.mf_engine.explain(
MetricFlowQueryRequest.create_with_random_request_id(
metric_names=("bookings",),
group_by_names=("metric_time",),
sql_optimization_level=SqlQueryOptimizationLevel.O0,
)
)

assert explain_result_at_default_level.rendered_sql.sql_query != explain_result_at_level_0.rendered_sql.sql_query

0 comments on commit e49bbce

Please sign in to comment.