Skip to content

Commit

Permalink
Update snapshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Jan 18, 2025
1 parent 29a4f0c commit 684c3c6
Showing 1 changed file with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
test_name: test_common_cte_aliases_in_nested_query
test_filename: test_cte_column_pruner.py
docstring:
Test the case where a CTE defined in the top-level SELECT has the same name as a CTE in a sub-query .
expectation_description:
In the `from_sub_query`, there is a reference to `cte_source__col_0` in a CTE named `cte_source`. Since
`from_sub_query` redefines `cte_source`, the column pruner should retain that column in the CTE defined
in `from_sub_query` but remove the column from the CTE defined in `from_sub_query`.
---
optimizer:
SqlColumnPrunerOptimizer

sql_before_optimizing:
-- top_level_select
WITH cte_source AS (
-- CTE source
SELECT
test_table_alias.col_0 AS cte_source__col_0
, test_table_alias.col_1 AS cte_source__col_1
FROM test_schema.test_table test_table_alias
)

SELECT
from_source_alias.from_source__col_0 AS top_level__col_0
, right_source_alias.right_source__col_1 AS top_level__col_1
FROM (
-- from_sub_query
WITH cte_source AS (
-- CTE source
SELECT
test_table_alias.col_0 AS cte_source__col_0
, test_table_alias.col_1 AS cte_source__col_1
FROM test_schema.test_table test_table_alias
)

SELECT
from_source_alias.cte_source__col_0 AS from_source__col_0
FROM cte_source from_source_alias
) from_source_alias
INNER JOIN (
-- joined_sub_query
SELECT
from_source_alias.cte_source__col_1 AS right_source__col_1
FROM cte_source from_source_alias
) right_source_alias
ON
from_source_alias.from_source__col_0 = right_source_alias.right_source__col_1

sql_after_optimizing:
-- top_level_select
WITH cte_source AS (
-- CTE source
SELECT
test_table_alias.col_1 AS cte_source__col_1
FROM test_schema.test_table test_table_alias
)

SELECT
from_source_alias.from_source__col_0 AS top_level__col_0
, right_source_alias.right_source__col_1 AS top_level__col_1
FROM (
-- from_sub_query
WITH cte_source AS (
-- CTE source
SELECT
test_table_alias.col_0 AS cte_source__col_0
FROM test_schema.test_table test_table_alias
)

SELECT
from_source_alias.cte_source__col_0 AS from_source__col_0
FROM cte_source from_source_alias
) from_source_alias
INNER JOIN (
-- joined_sub_query
SELECT
from_source_alias.cte_source__col_1 AS right_source__col_1
FROM cte_source from_source_alias
) right_source_alias
ON
from_source_alias.from_source__col_0 = right_source_alias.right_source__col_1

0 comments on commit 684c3c6

Please sign in to comment.