diff --git a/tests_metricflow/snapshots/test_cte_rewriting_sub_query_reducer.py/str/test_reduce_cte__result.txt b/tests_metricflow/snapshots/test_cte_rewriting_sub_query_reducer.py/str/test_reduce_cte__result.txt new file mode 100644 index 000000000..7b54c7ca0 --- /dev/null +++ b/tests_metricflow/snapshots/test_cte_rewriting_sub_query_reducer.py/str/test_reduce_cte__result.txt @@ -0,0 +1,81 @@ +test_name: test_reduce_cte +test_filename: test_cte_rewriting_sub_query_reducer.py +docstring: + Tests that the SELECT statements in CTEs are reduced. +--- +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 diff --git a/tests_metricflow/snapshots/test_cte_rewriting_sub_query_reducer.py/str/test_reduce_cte_with_use_column_alias_in_group_bys__result.txt b/tests_metricflow/snapshots/test_cte_rewriting_sub_query_reducer.py/str/test_reduce_cte_with_use_column_alias_in_group_bys__result.txt new file mode 100644 index 000000000..8f4b4238e --- /dev/null +++ b/tests_metricflow/snapshots/test_cte_rewriting_sub_query_reducer.py/str/test_reduce_cte_with_use_column_alias_in_group_bys__result.txt @@ -0,0 +1,81 @@ +test_name: test_reduce_cte_with_use_column_alias_in_group_bys +test_filename: test_cte_rewriting_sub_query_reducer.py +docstring: + This tests reducing with the `use_column_alias_in_group_bys` flag set. +--- +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 diff --git a/tests_metricflow/snapshots/test_rewriting_sub_query_reducer.py/SqlQueryPlan/test_reducing_join_statement__after_reducing.sql b/tests_metricflow/snapshots/test_rewriting_sub_query_reducer.py/SqlQueryPlan/test_reducing_join_statement__after_reducing.sql index a1377b889..04444e3b7 100644 --- a/tests_metricflow/snapshots/test_rewriting_sub_query_reducer.py/SqlQueryPlan/test_reducing_join_statement__after_reducing.sql +++ b/tests_metricflow/snapshots/test_rewriting_sub_query_reducer.py/SqlQueryPlan/test_reducing_join_statement__after_reducing.sql @@ -1,7 +1,7 @@ test_name: test_reducing_join_statement test_filename: test_rewriting_sub_query_reducer.py docstring: - Tests a case where a join query should not reduced an aggregate. + Tests a case where a join query should not reduce an aggregate. --- -- query SELECT diff --git a/tests_metricflow/snapshots/test_rewriting_sub_query_reducer.py/SqlQueryPlan/test_reducing_join_statement__before_reducing.sql b/tests_metricflow/snapshots/test_rewriting_sub_query_reducer.py/SqlQueryPlan/test_reducing_join_statement__before_reducing.sql index 520867500..f38e545db 100644 --- a/tests_metricflow/snapshots/test_rewriting_sub_query_reducer.py/SqlQueryPlan/test_reducing_join_statement__before_reducing.sql +++ b/tests_metricflow/snapshots/test_rewriting_sub_query_reducer.py/SqlQueryPlan/test_reducing_join_statement__before_reducing.sql @@ -1,7 +1,7 @@ test_name: test_reducing_join_statement test_filename: test_rewriting_sub_query_reducer.py docstring: - Tests a case where a join query should not reduced an aggregate. + Tests a case where a join query should not reduce an aggregate. --- -- query SELECT