-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/* PR_START p--cte 10 */ Support CTEs in table alias simplifier.
- Loading branch information
Showing
3 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
tests_metricflow/sql/optimizer/test_cte_table_alias_simplifier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
from _pytest.fixtures import FixtureRequest | ||
from metricflow_semantics.sql.sql_join_type import SqlJoinType | ||
from metricflow_semantics.sql.sql_table import SqlTable | ||
from metricflow_semantics.test_helpers.config_helpers import MetricFlowTestConfiguration | ||
|
||
from metricflow.sql.optimizer.table_alias_simplifier import SqlTableAliasSimplifier | ||
from metricflow.sql.render.sql_plan_renderer import DefaultSqlQueryPlanRenderer, SqlQueryPlanRenderer | ||
from metricflow.sql.sql_exprs import ( | ||
SqlColumnReference, | ||
SqlColumnReferenceExpression, | ||
SqlComparison, | ||
SqlComparisonExpression, | ||
) | ||
from metricflow.sql.sql_plan import ( | ||
SqlJoinDescription, | ||
SqlSelectColumn, | ||
SqlSelectStatementNode, | ||
SqlTableNode, | ||
) | ||
from tests_metricflow.sql.compare_sql_plan import assert_default_rendered_sql_equal | ||
from tests_metricflow.sql.optimizer.check_optimizer import assert_optimizer_result_snapshot_equal | ||
|
||
|
||
@pytest.fixture | ||
def sql_plan_renderer() -> DefaultSqlQueryPlanRenderer: # noqa: D103 | ||
return DefaultSqlQueryPlanRenderer() | ||
|
||
|
||
def test_table_alias_simplification( | ||
request: FixtureRequest, | ||
mf_test_configuration: MetricFlowTestConfiguration, | ||
sql_plan_renderer: DefaultSqlQueryPlanRenderer, | ||
base_select_statement: SqlSelectStatementNode, | ||
) -> None: | ||
"""Tests that table aliases are removed when not needed in CTEs.""" | ||
|
||
assert_optimizer_result_snapshot_equal( | ||
request=request, | ||
mf_test_configuration=mf_test_configuration, | ||
optimizer=SqlTableAliasSimplifier(), | ||
sql_plan_renderer=sql_plan_renderer, | ||
select_statement=base_select_statement, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters