You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ya...@apache.org on 2022/11/17 05:20:12 UTC

[arrow-datafusion] branch master updated: fix conflict and UT, cleanup redundant legacy code (#4252)

This is an automated email from the ASF dual-hosted git repository.

yangjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new 7a81e9fb5 fix conflict and UT, cleanup redundant legacy code (#4252)
7a81e9fb5 is described below

commit 7a81e9fb5382612c75bee0b4c46494a20e9fd7da
Author: jakevin <ja...@gmail.com>
AuthorDate: Thu Nov 17 13:20:06 2022 +0800

    fix conflict and UT, cleanup redundant legacy code (#4252)
    
    * fix conflict and UT, cleanup redundant legacy code
    
    * fix fmt
---
 datafusion/expr/src/lib.rs                         |  2 +-
 datafusion/expr/src/logical_plan/builder.rs        | 31 ++++------------------
 datafusion/optimizer/src/filter_push_down.rs       | 26 ++----------------
 .../optimizer/src/propagate_empty_relation.rs      |  9 +++----
 4 files changed, 11 insertions(+), 57 deletions(-)

diff --git a/datafusion/expr/src/lib.rs b/datafusion/expr/src/lib.rs
index 45c281551..c8958cb23 100644
--- a/datafusion/expr/src/lib.rs
+++ b/datafusion/expr/src/lib.rs
@@ -67,7 +67,7 @@ pub use function::{
 };
 pub use literal::{lit, lit_timestamp_nano, Literal, TimestampLiteral};
 pub use logical_plan::{
-    builder::{build_join_schema, union_with_alias, UNNAMED_TABLE},
+    builder::{build_join_schema, union, UNNAMED_TABLE},
     Aggregate, CreateCatalog, CreateCatalogSchema, CreateExternalTable,
     CreateMemoryTable, CreateView, CrossJoin, Distinct, DropTable, DropView,
     EmptyRelation, Explain, Extension, Filter, Join, JoinConstraint, JoinType, Limit,
diff --git a/datafusion/expr/src/logical_plan/builder.rs b/datafusion/expr/src/logical_plan/builder.rs
index dedd8d7b8..1bbaf6da9 100644
--- a/datafusion/expr/src/logical_plan/builder.rs
+++ b/datafusion/expr/src/logical_plan/builder.rs
@@ -416,19 +416,7 @@ impl LogicalPlanBuilder {
 
     /// Apply a union, preserving duplicate rows
     pub fn union(&self, plan: LogicalPlan) -> Result<Self> {
-        Ok(Self::from(union_with_alias(self.plan.clone(), plan, None)?))
-    }
-
-    pub fn union_with_alias(
-        &self,
-        plan: LogicalPlan,
-        alias: Option<String>,
-    ) -> Result<Self> {
-        Ok(Self::from(union_with_alias(
-            self.plan.clone(),
-            plan,
-            alias,
-        )?))
+        Ok(Self::from(union(self.plan.clone(), plan)?))
     }
 
     /// Apply a union, removing duplicate rows
@@ -445,7 +433,7 @@ impl LogicalPlanBuilder {
         };
 
         Ok(Self::from(LogicalPlan::Distinct(Distinct {
-            input: Arc::new(union_with_alias(left_plan, right_plan, None)?),
+            input: Arc::new(union(left_plan, right_plan)?),
         })))
     }
 
@@ -892,11 +880,7 @@ pub fn project_with_column_index_alias(
 }
 
 /// Union two logical plans with an optional alias.
-pub fn union_with_alias(
-    left_plan: LogicalPlan,
-    right_plan: LogicalPlan,
-    alias: Option<String>,
-) -> Result<LogicalPlan> {
+pub fn union(left_plan: LogicalPlan, right_plan: LogicalPlan) -> Result<LogicalPlan> {
     let left_col_num = left_plan.schema().fields().len();
 
     // the 2 queries should have same number of columns
@@ -927,7 +911,7 @@ pub fn union_with_alias(
                     })?;
 
             Ok(DFField::new(
-                alias.as_deref(),
+                None,
                 left_field.name(),
                 data_type,
                 nullable,
@@ -962,14 +946,9 @@ pub fn union_with_alias(
         return Err(DataFusionError::Plan("Empty UNION".to_string()));
     }
 
-    let union_schema = Arc::new(match alias {
-        Some(ref alias) => union_schema.replace_qualifier(alias.as_str()),
-        None => union_schema.strip_qualifiers(),
-    });
-
     Ok(LogicalPlan::Union(Union {
         inputs,
-        schema: union_schema,
+        schema: Arc::new(union_schema),
     }))
 }
 
diff --git a/datafusion/optimizer/src/filter_push_down.rs b/datafusion/optimizer/src/filter_push_down.rs
index 7bcd03565..9ba30fae5 100644
--- a/datafusion/optimizer/src/filter_push_down.rs
+++ b/datafusion/optimizer/src/filter_push_down.rs
@@ -833,9 +833,8 @@ mod tests {
     use async_trait::async_trait;
     use datafusion_common::DFSchema;
     use datafusion_expr::{
-        and, col, in_list, in_subquery, lit,
-        logical_plan::{builder::union_with_alias, JoinType},
-        sum, Expr, LogicalPlanBuilder, Operator, TableSource, TableType,
+        and, col, in_list, in_subquery, lit, logical_plan::JoinType, sum, Expr,
+        LogicalPlanBuilder, Operator, TableSource, TableType,
     };
     use std::sync::Arc;
 
@@ -1183,27 +1182,6 @@ mod tests {
         Ok(())
     }
 
-    #[test]
-    fn union_all_with_alias() -> Result<()> {
-        let table_scan = test_table_scan()?;
-        let union =
-            union_with_alias(table_scan.clone(), table_scan, Some("t".to_string()))?;
-
-        let plan = LogicalPlanBuilder::from(union)
-            .filter(col("t.a").eq(lit(1i64)))?
-            .build()?;
-
-        // filter appears below Union without relation qualifier
-        let expected = "\
-            Union\
-            \n  Filter: a = Int64(1)\
-            \n    TableScan: test\
-            \n  Filter: a = Int64(1)\
-            \n    TableScan: test";
-        assert_optimized_plan_eq(&plan, expected);
-        Ok(())
-    }
-
     #[test]
     fn union_all_on_projection() -> Result<()> {
         let table_scan = test_table_scan()?;
diff --git a/datafusion/optimizer/src/propagate_empty_relation.rs b/datafusion/optimizer/src/propagate_empty_relation.rs
index 59f88cef6..c1a95c8d3 100644
--- a/datafusion/optimizer/src/propagate_empty_relation.rs
+++ b/datafusion/optimizer/src/propagate_empty_relation.rs
@@ -120,14 +120,13 @@ impl OptimizerRule for PropagateEmptyRelation {
                         Ok(LogicalPlan::Projection(Projection::new_from_schema(
                             Arc::new(child),
                             optimized_children_plan.schema().clone(),
-                            union.alias.clone(),
+                            None,
                         )))
                     }
                 } else {
                     Ok(LogicalPlan::Union(Union {
                         inputs: new_inputs,
                         schema: union.schema.clone(),
-                        alias: union.alias.clone(),
                     }))
                 }
             }
@@ -383,11 +382,9 @@ mod tests {
             .filter(Expr::Literal(ScalarValue::Boolean(Some(false))))?
             .build()?;
 
-        let plan = LogicalPlanBuilder::from(left)
-            .union_with_alias(right, Some("union".to_string()))?
-            .build()?;
+        let plan = LogicalPlanBuilder::from(left).union(right)?.build()?;
 
-        let expected = "Projection: union.a, union.b, union.c, alias=union\
+        let expected = "Projection: a, b, c\
             \n  TableScan: test";
         assert_together_optimized_plan_eq(&plan, expected);
         Ok(())