-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for rewriting queries with CTEs.
- Loading branch information
Showing
3 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...ricflow/snapshots/test_cte_rewriting_sub_query_reducer.py/str/test_reduce_cte__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,76 @@ | ||
optimizer: | ||
SqlRewritingSubQueryReducer | ||
|
||
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 | ||
GROUP BY | ||
cte_source_0_alias.cte_source_0__col_0 | ||
, right_source_alias.right_source__col_1 | ||
|
||
sql_after_optimizing: | ||
-- Top-level SELECT | ||
WITH cte_source_0 AS ( | ||
-- CTE source 0 sub-query | ||
-- 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 test_schema.test_table test_table_alias | ||
) | ||
|
||
, cte_source_1 AS ( | ||
-- CTE source 1 sub-query | ||
-- 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_0 cte_source_0_alias | ||
) | ||
|
||
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 | ||
GROUP BY | ||
cte_source_0_alias.cte_source_0__col_0 | ||
, right_source_alias.right_source__col_1 |
76 changes: 76 additions & 0 deletions
76
...g_sub_query_reducer.py/str/test_reduce_cte_with_use_column_alias_in_group_bys__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,76 @@ | ||
optimizer: | ||
SqlRewritingSubQueryReducer | ||
|
||
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 | ||
GROUP BY | ||
cte_source_0_alias.cte_source_0__col_0 | ||
, right_source_alias.right_source__col_1 | ||
|
||
sql_after_optimizing: | ||
-- Top-level SELECT | ||
WITH cte_source_0 AS ( | ||
-- CTE source 0 sub-query | ||
-- 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 test_schema.test_table test_table_alias | ||
) | ||
|
||
, cte_source_1 AS ( | ||
-- CTE source 1 sub-query | ||
-- 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_0 cte_source_0_alias | ||
) | ||
|
||
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 | ||
GROUP BY | ||
top_level__col_0 | ||
, top_level__col_1 |
Oops, something went wrong.