-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
SqlTableAliasSimplifier
to handle CTEs (#1516)
Similar to the updates for the other optimizers in #1503 and #1504, this PR implements the CTE case for the `SqlTableAliasSimplifier`
- Loading branch information
Showing
7 changed files
with
374 additions
and
6 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
41 changes: 41 additions & 0 deletions
41
...ots/test_cte_table_alias_simplifier.py/str/test_table_alias_no_simplification__result.txt
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,41 @@ | ||
test_name: test_table_alias_no_simplification | ||
test_filename: test_cte_table_alias_simplifier.py | ||
docstring: | ||
Tests that table aliases in the SELECT statement of a CTE are not removed when required. | ||
--- | ||
optimizer: | ||
SqlTableAliasSimplifier | ||
|
||
sql_before_optimizing: | ||
-- Top-level SELECT | ||
WITH cte_source_0 AS ( | ||
-- CTE source 0 | ||
SELECT | ||
from_source_alias.col_0 AS cte_source_0__col_0 | ||
FROM test_schema.test_table_0 from_source_alias | ||
INNER JOIN | ||
test_schema.test_table_1 right_source_alias | ||
ON | ||
from_source_alias.col_0 = right_source_alias.col_0 | ||
) | ||
|
||
SELECT | ||
cte_source_0_alias.cte_source_0__col_0 AS top_level__col_0 | ||
FROM cte_source_0 cte_source_0_alias | ||
|
||
sql_after_optimizing: | ||
-- Top-level SELECT | ||
WITH cte_source_0 AS ( | ||
-- CTE source 0 | ||
SELECT | ||
from_source_alias.col_0 AS cte_source_0__col_0 | ||
FROM test_schema.test_table_0 from_source_alias | ||
INNER JOIN | ||
test_schema.test_table_1 right_source_alias | ||
ON | ||
from_source_alias.col_0 = right_source_alias.col_0 | ||
) | ||
|
||
SELECT | ||
cte_source_0__col_0 AS top_level__col_0 | ||
FROM cte_source_0 cte_source_0_alias |
85 changes: 85 additions & 0 deletions
85
...pshots/test_cte_table_alias_simplifier.py/str/test_table_alias_simplification__result.txt
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,85 @@ | ||
test_name: test_table_alias_simplification | ||
test_filename: test_cte_table_alias_simplifier.py | ||
docstring: | ||
Tests that table aliases in the SELECT statement of a CTE are removed when not needed. | ||
--- | ||
optimizer: | ||
SqlTableAliasSimplifier | ||
|
||
sql_before_optimizing: | ||
-- Top-level SELECT | ||
WITH cte_source_0 AS ( | ||
-- CTE source 0 | ||
SELECT | ||
test_table_alias.col_0 AS cte_source_0__col_0 | ||
, test_table_alias.col_1 AS cte_source_0__col_1 | ||
FROM ( | ||
-- CTE source 0 sub-query | ||
SELECT | ||
test_table_alias.col_0 AS cte_source_0_subquery__col_0 | ||
, test_table_alias.col_0 AS cte_source_0_subquery__col_1 | ||
FROM test_schema.test_table test_table_alias | ||
) cte_source_0_subquery | ||
) | ||
|
||
, cte_source_1 AS ( | ||
-- CTE source 1 | ||
SELECT | ||
test_table_alias.col_0 AS cte_source_1__col_0 | ||
, test_table_alias.col_1 AS cte_source_1__col_1 | ||
FROM ( | ||
-- CTE source 1 sub-query | ||
SELECT | ||
cte_source_0_alias.cte_source_0__col_0 AS cte_source_1_subquery__col_0 | ||
, cte_source_0_alias.cte_source_0__col_0 AS cte_source_1_subquery__col_1 | ||
FROM cte_source_0 cte_source_0_alias | ||
) cte_source_1_subquery | ||
) | ||
|
||
SELECT | ||
cte_source_0_alias.cte_source_0__col_0 AS top_level__col_0 | ||
, right_source_alias.right_source__col_1 AS top_level__col_1 | ||
FROM cte_source_0 cte_source_0_alias | ||
INNER JOIN | ||
cte_source_1 right_source_alias | ||
ON | ||
cte_source_0_alias.cte_source_0__col_1 = right_source_alias.right_source__col_1 | ||
|
||
sql_after_optimizing: | ||
-- Top-level SELECT | ||
WITH cte_source_0 AS ( | ||
-- CTE source 0 | ||
SELECT | ||
col_0 AS cte_source_0__col_0 | ||
, col_1 AS cte_source_0__col_1 | ||
FROM ( | ||
-- CTE source 0 sub-query | ||
SELECT | ||
col_0 AS cte_source_0_subquery__col_0 | ||
, col_0 AS cte_source_0_subquery__col_1 | ||
FROM test_schema.test_table test_table_alias | ||
) cte_source_0_subquery | ||
) | ||
|
||
, cte_source_1 AS ( | ||
-- CTE source 1 | ||
SELECT | ||
col_0 AS cte_source_1__col_0 | ||
, col_1 AS cte_source_1__col_1 | ||
FROM ( | ||
-- CTE source 1 sub-query | ||
SELECT | ||
cte_source_0__col_0 AS cte_source_1_subquery__col_0 | ||
, cte_source_0__col_0 AS cte_source_1_subquery__col_1 | ||
FROM cte_source_0 cte_source_0_alias | ||
) cte_source_1_subquery | ||
) | ||
|
||
SELECT | ||
cte_source_0_alias.cte_source_0__col_0 AS top_level__col_0 | ||
, right_source_alias.right_source__col_1 AS top_level__col_1 | ||
FROM cte_source_0 cte_source_0_alias | ||
INNER JOIN | ||
cte_source_1 right_source_alias | ||
ON | ||
cte_source_0_alias.cte_source_0__col_1 = right_source_alias.right_source__col_1 |
2 changes: 1 addition & 1 deletion
2
...implifier.py/SqlQueryPlan/test_table_alias_simplification__after_alias_simplification.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
2 changes: 1 addition & 1 deletion
2
...mplifier.py/SqlQueryPlan/test_table_alias_simplification__before_alias_simplification.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
Oops, something went wrong.