-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with missed columns in the column pruner (#1679)
This PR fixes a bug where the column pruner does not correctly keep track of columns that are used in `SqlStringExpression` and `SqlColumnAliasReferenceExpression`. Those expressions are different from other expressions as they do not have a table alias, and there is existing case handling for those expressions. The bug is that the handler did not propagate the knowledge that columns from those expressions is required to the available CTEs. This bug currently does not affect queries due to the way that we wrap access to CTEs in a `SELECT`, but fixing this as it affects later work.
- Loading branch information
Showing
4 changed files
with
188 additions
and
0 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
36 changes: 36 additions & 0 deletions
36
...flow/snapshots/test_cte_column_pruner.py/str/test_column_reference_expression__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,36 @@ | ||
test_name: test_column_reference_expression | ||
test_filename: test_cte_column_pruner.py | ||
docstring: | ||
Test a column reference expression that does not specify a table alias. | ||
expectation_description: | ||
`cte_source_0__col_01` should be retained in the CTE. | ||
--- | ||
optimizer: | ||
SqlColumnPrunerOptimizer | ||
|
||
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_0 AS cte_source_0__col_1 | ||
FROM test_schema.test_table test_table_alias | ||
) | ||
|
||
SELECT | ||
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 | ||
test_table_alias.col_0 AS cte_source_0__col_0 | ||
FROM test_schema.test_table test_table_alias | ||
) | ||
|
||
SELECT | ||
cte_source_0__col_0 AS top_level__col_0 | ||
FROM cte_source_0 cte_source_0_alias |
36 changes: 36 additions & 0 deletions
36
tests_metricflow/snapshots/test_cte_column_pruner.py/str/test_string_expression__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,36 @@ | ||
test_name: test_string_expression | ||
test_filename: test_cte_column_pruner.py | ||
docstring: | ||
Test a string expression that references a column in the cte. | ||
expectation_description: | ||
`cte_source_0__col_01` should be retained in the CTE. | ||
--- | ||
optimizer: | ||
SqlColumnPrunerOptimizer | ||
|
||
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_0 AS cte_source_0__col_1 | ||
FROM test_schema.test_table test_table_alias | ||
) | ||
|
||
SELECT | ||
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 | ||
test_table_alias.col_0 AS cte_source_0__col_0 | ||
FROM test_schema.test_table test_table_alias | ||
) | ||
|
||
SELECT | ||
cte_source_0__col_0 AS top_level__col_0 | ||
FROM cte_source_0 cte_source_0_alias |
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