-
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.
- Loading branch information
Showing
2 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...s_metricflow/snapshots/test_render_cte.py/SqlQueryPlan/DuckDB/test_render_cte__plan_0.sql
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,23 @@ | ||
-- cte_test | ||
WITH cte_0 AS ( | ||
-- cte_select_0 | ||
SELECT | ||
cte_source_table_0.col_0 | ||
FROM demo.cte_source_table_0 cte_source_table_0 | ||
) | ||
|
||
, cte_1 AS ( | ||
-- cte_select_1 | ||
SELECT | ||
cte_source_table_1.col_1 | ||
FROM demo.cte_source_table_1 cte_source_table_1 | ||
) | ||
|
||
SELECT | ||
cte_0.col_0 AS col_0 | ||
, cte_1.col_1 AS col_1 | ||
FROM cte_0 cte_0 | ||
LEFT OUTER JOIN | ||
cte_1 cte_1 | ||
ON | ||
cte_0.col_0 = cte_1.col_1 |
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,114 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
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.protocols.sql_client import SqlClient | ||
from metricflow.sql.sql_exprs import ( | ||
SqlColumnReference, | ||
SqlColumnReferenceExpression, | ||
SqlComparison, | ||
SqlComparisonExpression, | ||
) | ||
from metricflow.sql.sql_plan import ( | ||
SqlCteNode, | ||
SqlJoinDescription, | ||
SqlSelectColumn, | ||
SqlSelectStatementNode, | ||
SqlTableNode, | ||
) | ||
from tests_metricflow.sql.compare_sql_plan import assert_rendered_sql_equal | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.mark.sql_engine_snapshot | ||
def test_render_cte( # noqa: D103 | ||
request: FixtureRequest, | ||
mf_test_configuration: MetricFlowTestConfiguration, | ||
sql_client: SqlClient, | ||
) -> None: | ||
assert_rendered_sql_equal( | ||
request=request, | ||
mf_test_configuration=mf_test_configuration, | ||
sql_plan_node=SqlSelectStatementNode.create( | ||
description="cte_test", | ||
select_columns=( | ||
SqlSelectColumn( | ||
expr=SqlColumnReferenceExpression.create( | ||
col_ref=SqlColumnReference(table_alias="cte_0", column_name="col_0") | ||
), | ||
column_alias="col_0", | ||
), | ||
SqlSelectColumn( | ||
expr=SqlColumnReferenceExpression.create( | ||
col_ref=SqlColumnReference(table_alias="cte_1", column_name="col_1") | ||
), | ||
column_alias="col_1", | ||
), | ||
), | ||
from_source=SqlTableNode.create(sql_table=SqlTable(schema_name=None, table_name="cte_0")), | ||
from_source_alias="cte_0", | ||
join_descs=( | ||
SqlJoinDescription( | ||
right_source=SqlTableNode.create(sql_table=SqlTable(schema_name=None, table_name="cte_1")), | ||
right_source_alias="cte_1", | ||
join_type=SqlJoinType.LEFT_OUTER, | ||
on_condition=SqlComparisonExpression.create( | ||
left_expr=SqlColumnReferenceExpression.create( | ||
col_ref=SqlColumnReference(table_alias="cte_0", column_name="col_0") | ||
), | ||
comparison=SqlComparison.EQUALS, | ||
right_expr=SqlColumnReferenceExpression.create( | ||
col_ref=SqlColumnReference(table_alias="cte_1", column_name="col_1") | ||
), | ||
), | ||
), | ||
), | ||
cte_sources=( | ||
SqlCteNode.create( | ||
select_statement=SqlSelectStatementNode.create( | ||
description="cte_select_0", | ||
select_columns=( | ||
SqlSelectColumn( | ||
expr=SqlColumnReferenceExpression.create( | ||
col_ref=SqlColumnReference(table_alias="cte_source_table_0", column_name="col_0") | ||
), | ||
column_alias="col_0", | ||
), | ||
), | ||
from_source=SqlTableNode.create( | ||
sql_table=SqlTable(schema_name="demo", table_name="cte_source_table_0") | ||
), | ||
from_source_alias="cte_source_table_0", | ||
), | ||
cte_alias="cte_0", | ||
), | ||
SqlCteNode.create( | ||
select_statement=SqlSelectStatementNode.create( | ||
description="cte_select_1", | ||
select_columns=( | ||
SqlSelectColumn( | ||
expr=SqlColumnReferenceExpression.create( | ||
col_ref=SqlColumnReference(table_alias="cte_source_table_1", column_name="col_1") | ||
), | ||
column_alias="col_1", | ||
), | ||
), | ||
from_source=SqlTableNode.create( | ||
sql_table=SqlTable(schema_name="demo", table_name="cte_source_table_1") | ||
), | ||
from_source_alias="cte_source_table_1", | ||
), | ||
cte_alias="cte_1", | ||
), | ||
), | ||
), | ||
plan_id="plan_0", | ||
sql_client=sql_client, | ||
) |