You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/26 05:43:12 UTC

[GitHub] [arrow-datafusion] AssHero commented on a diff in pull request #4379: refine the code of build schema for ambiguous check, factor this out into a function

AssHero commented on code in PR #4379:
URL: https://github.com/apache/arrow-datafusion/pull/4379#discussion_r1032743440


##########
datafusion/sql/src/planner.rs:
##########
@@ -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)?;

Review Comment:
   Hi @alamb, this is the follow up PR to factor this part into a function 'build_schema_for_ambiguous_check'.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org