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

[arrow-datafusion] branch master updated: refactor: remove redundant `build_join_schema()` (#4538)

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

alamb 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 5f742841b refactor: remove redundant `build_join_schema()` (#4538)
5f742841b is described below

commit 5f742841bb523b1336a082cce148564158fea911
Author: jakevin <ja...@gmail.com>
AuthorDate: Wed Dec 7 19:36:16 2022 +0800

    refactor: remove redundant `build_join_schema()` (#4538)
---
 datafusion/optimizer/src/eliminate_cross_join.rs | 29 +++++++++++-------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/datafusion/optimizer/src/eliminate_cross_join.rs b/datafusion/optimizer/src/eliminate_cross_join.rs
index 83fc9e164..e255fe921 100644
--- a/datafusion/optimizer/src/eliminate_cross_join.rs
+++ b/datafusion/optimizer/src/eliminate_cross_join.rs
@@ -17,9 +17,9 @@
 
 //! Optimizer rule to eliminate cross join to inner join if join predicates are available in filters.
 use crate::{utils, OptimizerConfig, OptimizerRule};
-use datafusion_common::{Column, DFSchema, DataFusionError, Result};
+use datafusion_common::{Column, DataFusionError, Result};
 use datafusion_expr::{
-    and,
+    and, build_join_schema,
     expr::BinaryExpr,
     logical_plan::{CrossJoin, Filter, Join, JoinType, LogicalPlan},
     or,
@@ -28,7 +28,7 @@ use datafusion_expr::{
 };
 use datafusion_expr::{Expr, Operator};
 
-use std::collections::{HashMap, HashSet};
+use std::collections::HashSet;
 
 //use std::collections::HashMap;
 use datafusion_expr::logical_plan::JoinConstraint;
@@ -207,7 +207,11 @@ fn find_inner_join(
         if !join_keys.is_empty() {
             all_join_keys.extend(join_keys.clone());
             let right = rights.remove(i);
-            let join_schema = Arc::new(build_join_schema(left, &right)?);
+            let join_schema = Arc::new(build_join_schema(
+                left.schema(),
+                right.schema(),
+                &JoinType::Inner,
+            )?);
             return Ok(LogicalPlan::Join(Join {
                 left: Arc::new(left.clone()),
                 right: Arc::new(right),
@@ -221,7 +225,11 @@ fn find_inner_join(
         }
     }
     let right = rights.remove(0);
-    let join_schema = Arc::new(build_join_schema(left, &right)?);
+    let join_schema = Arc::new(build_join_schema(
+        left.schema(),
+        right.schema(),
+        &JoinType::Inner,
+    )?);
 
     Ok(LogicalPlan::CrossJoin(CrossJoin {
         left: Arc::new(left.clone()),
@@ -230,17 +238,6 @@ fn find_inner_join(
     }))
 }
 
-fn build_join_schema(left: &LogicalPlan, right: &LogicalPlan) -> Result<DFSchema> {
-    // build join schema
-    let mut fields = vec![];
-    let mut metadata = HashMap::new();
-    fields.extend(left.schema().fields().clone());
-    fields.extend(right.schema().fields().clone());
-    metadata.extend(left.schema().metadata().clone());
-    metadata.extend(right.schema().metadata().clone());
-    DFSchema::new_with_metadata(fields, metadata)
-}
-
 fn intersect(
     accum: &mut Vec<(Column, Column)>,
     vec1: &[(Column, Column)],