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/11/26 12:44:47 UTC

[arrow-datafusion] branch master updated: refine the code of build schema for ambiguous check, factor this out into a function (#4379)

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 12b5a1bfe refine the code of build schema for ambiguous check, factor this out into a function (#4379)
12b5a1bfe is described below

commit 12b5a1bfec9ebce1cca661d4d2dd5890b086895a
Author: AssHero <hu...@gmail.com>
AuthorDate: Sat Nov 26 20:44:41 2022 +0800

    refine the code of build schema for ambiguous check, factor this out into a function (#4379)
---
 datafusion/sql/src/planner.rs | 55 +++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index 4e4ca02f6..ad57f7eb6 100644
--- a/datafusion/sql/src/planner.rs
+++ b/datafusion/sql/src/planner.rs
@@ -990,6 +990,33 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
         }
     }
 
+    /// build schema for unqualifier column ambiguous check
+    fn build_schema_for_ambiguous_check(&self, plan: &LogicalPlan) -> Result<DFSchema> {
+        let mut fields = plan.schema().fields().clone();
+
+        let metadata = plan.schema().metadata().clone();
+        if let LogicalPlan::Join(HashJoin {
+            join_constraint: HashJoinConstraint::Using,
+            ref on,
+            ref left,
+            ..
+        }) = plan
+        {
+            // For query: select id from t1 join t2 using(id), this is legal.
+            // We should dedup the fields for cols in using clause.
+            for join_cols in on.iter() {
+                let left_field = left.schema().field_from_column(&join_cols.0)?;
+                fields.retain(|field| {
+                    field.unqualified_column().name
+                        != left_field.unqualified_column().name
+                });
+                fields.push(left_field.clone());
+            }
+        }
+
+        DFSchema::new_with_metadata(fields, metadata)
+    }
+
     /// Generate a logic plan from an SQL select
     fn select_to_plan(
         &self,
@@ -1016,32 +1043,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
         let plan = self.plan_from_tables(select.from, ctes, outer_query_schema)?;
         let empty_from = matches!(plan, LogicalPlan::EmptyRelation(_));
         // build from schema for unqualifier column ambiguous check
-        // we should get only one field for this unqualifier column from schema.
-        let from_schema = {
-            let mut fields = plan.schema().fields().clone();
-
-            let metadata = plan.schema().metadata().clone();
-            if let LogicalPlan::Join(HashJoin {
-                join_constraint: HashJoinConstraint::Using,
-                ref on,
-                ref left,
-                ..
-            }) = plan
-            {
-                // For query: select id from t1 join t2 using(id), this is legal.
-                // We should dedup the fields for cols in using clause.
-                for join_cols in on.iter() {
-                    let left_field = left.schema().field_from_column(&join_cols.0)?;
-                    fields.retain(|field| {
-                        field.unqualified_column().name
-                            != left_field.unqualified_column().name
-                    });
-                    fields.push(left_field.clone());
-                }
-            }
-
-            DFSchema::new_with_metadata(fields, metadata)?
-        };
+        // we should get only one field for unqualifier column from schema.
+        let from_schema = self.build_schema_for_ambiguous_check(&plan)?;
 
         // process `where` clause
         let plan =