Skip to content

Apache DataFusion SQL Query Engine

Move merge projections tests to under optimize projections (#8352)

Mustafa Akur4c914ea1e5d3
diff --git a/datafusion/optimizer/src/lib.rs b/datafusion/optimizer/src/lib.rs
index d8b0c14589..b54facc5d6 100644
--- a/datafusion/optimizer/src/lib.rs
+++ b/datafusion/optimizer/src/lib.rs
@@ -29,7 +29,6 @@ pub mod eliminate_one_union;
pub mod eliminate_outer_join;
pub mod extract_equijoin_predicate;
pub mod filter_null_join_keys;
-pub mod merge_projection;
pub mod optimize_projections;
pub mod optimizer;
pub mod propagate_empty_relation;
diff --git a/datafusion/optimizer/src/merge_projection.rs b/datafusion/optimizer/src/merge_projection.rs
deleted file mode 100644
index f7b750011e..0000000000
--- a/datafusion/optimizer/src/merge_projection.rs
+++ /dev/null
@@ -1,73 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#[cfg(test)]
-mod tests {
- use crate::optimize_projections::OptimizeProjections;
- use datafusion_common::Result;
- use datafusion_expr::{
- binary_expr, col, lit, logical_plan::builder::LogicalPlanBuilder, LogicalPlan,
- Operator,
- };
- use std::sync::Arc;
-
- use crate::test::*;
-
- fn assert_optimized_plan_equal(plan: &LogicalPlan, expected: &str) -> Result<()> {
- assert_optimized_plan_eq(Arc::new(OptimizeProjections::new()), plan, expected)
- }
-
- #[test]
- fn merge_two_projection() -> Result<()> {
- let table_scan = test_table_scan()?;
- let plan = LogicalPlanBuilder::from(table_scan)
- .project(vec![col("a")])?
- .project(vec![binary_expr(lit(1), Operator::Plus, col("a"))])?
- .build()?;
-
- let expected = "Projection: Int32(1) + test.a\
- \n TableScan: test projection=[a]";
- assert_optimized_plan_equal(&plan, expected)
- }
-
- #[test]
- fn merge_three_projection() -> Result<()> {
- let table_scan = test_table_scan()?;
- let plan = LogicalPlanBuilder::from(table_scan)
- .project(vec![col("a"), col("b")])?
- .project(vec![col("a")])?
- .project(vec![binary_expr(lit(1), Operator::Plus, col("a"))])?
- .build()?;
-
- let expected = "Projection: Int32(1) + test.a\
- \n TableScan: test projection=[a]";
- assert_optimized_plan_equal(&plan, expected)
- }
-
- #[test]
- fn merge_alias() -> Result<()> {
- let table_scan = test_table_scan()?;
- let plan = LogicalPlanBuilder::from(table_scan)
- .project(vec![col("a")])?
- .project(vec![col("a").alias("alias")])?
- .build()?;
-
- let expected = "Projection: test.a AS alias\
- \n TableScan: test projection=[a]";
- assert_optimized_plan_equal(&plan, expected)
- }
-}
diff --git a/datafusion/optimizer/src/optimize_projections.rs b/datafusion/optimizer/src/optimize_projections.rs
index 3d0565a6af..1e98ee76d2 100644
--- a/datafusion/optimizer/src/optimize_projections.rs
+++ b/datafusion/optimizer/src/optimize_projections.rs
@@ -846,3 +846,60 @@ fn rewrite_projection_given_requirements(
Ok(None)
};
}
+
+#[cfg(test)]
+mod tests {
+ use crate::optimize_projections::OptimizeProjections;
+ use datafusion_common::Result;
+ use datafusion_expr::{
+ binary_expr, col, lit, logical_plan::builder::LogicalPlanBuilder, LogicalPlan,
+ Operator,
+ };
+ use std::sync::Arc;
+
+ use crate::test::*;
+
+ fn assert_optimized_plan_equal(plan: &LogicalPlan, expected: &str) -> Result<()> {
+ assert_optimized_plan_eq(Arc::new(OptimizeProjections::new()), plan, expected)
+ }
+
+ #[test]
+ fn merge_two_projection() -> Result<()> {
+ let table_scan = test_table_scan()?;
+ let plan = LogicalPlanBuilder::from(table_scan)
+ .project(vec![col("a")])?
+ .project(vec![binary_expr(lit(1), Operator::Plus, col("a"))])?
+ .build()?;
+
+ let expected = "Projection: Int32(1) + test.a\
+ \n TableScan: test projection=[a]";
+ assert_optimized_plan_equal(&plan, expected)
+ }
+
+ #[test]
+ fn merge_three_projection() -> Result<()> {
+ let table_scan = test_table_scan()?;
+ let plan = LogicalPlanBuilder::from(table_scan)
+ .project(vec![col("a"), col("b")])?
+ .project(vec![col("a")])?
+ .project(vec![binary_expr(lit(1), Operator::Plus, col("a"))])?
+ .build()?;
+
+ let expected = "Projection: Int32(1) + test.a\
+ \n TableScan: test projection=[a]";
+ assert_optimized_plan_equal(&plan, expected)
+ }
+
+ #[test]
+ fn merge_alias() -> Result<()> {
+ let table_scan = test_table_scan()?;
+ let plan = LogicalPlanBuilder::from(table_scan)
+ .project(vec![col("a")])?
+ .project(vec![col("a").alias("alias")])?
+ .build()?;
+
+ let expected = "Projection: test.a AS alias\
+ \n TableScan: test projection=[a]";
+ assert_optimized_plan_equal(&plan, expected)
+ }
+}