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 2021/08/03 21:06:24 UTC

[GitHub] [arrow-datafusion] seddonm1 commented on a change in pull request #797: Better join order resolution logic

seddonm1 commented on a change in pull request #797:
URL: https://github.com/apache/arrow-datafusion/pull/797#discussion_r682102395



##########
File path: datafusion/src/logical_plan/builder.rs
##########
@@ -287,16 +287,125 @@ impl LogicalPlanBuilder {
                 .into_iter()
                 .zip(join_keys.1.into_iter())
                 .map(|(l, r)| {
-                    let mut swap = false;
                     let l = l.into();
-                    let left_key = l.clone().normalize(&self.plan).or_else(|_| {
-                        swap = true;
-                        l.normalize(right)
-                    });
-                    if swap {
-                        (r.into().normalize(&self.plan), left_key)
-                    } else {
-                        (left_key, r.into().normalize(right))
+                    let r = r.into();
+                    let lr = l.relation.clone();
+                    let rr = r.relation.clone();
+
+                    match (lr, rr) {
+                        (Some(lr), Some(rr)) => {
+                            let l_is_left =
+                                self.plan.all_schemas().iter().any(|schema| {
+                                    schema.fields().iter().any(|field| {
+                                        field.qualifier().unwrap() == &lr
+                                            && field.name() == &l.name
+                                    })
+                                });
+                            let l_is_right = right.all_schemas().iter().any(|schema| {
+                                schema.fields().iter().any(|field| {
+                                    field.qualifier().unwrap() == &lr
+                                        && field.name() == &l.name
+                                })
+                            });
+                            let r_is_left =
+                                self.plan.all_schemas().iter().any(|schema| {
+                                    schema.fields().iter().any(|field| {
+                                        field.qualifier().unwrap() == &rr
+                                            && field.name() == &r.name
+                                    })
+                                });
+                            let r_is_right = right.all_schemas().iter().any(|schema| {
+                                schema.fields().iter().any(|field| {
+                                    field.qualifier().unwrap() == &rr
+                                        && field.name() == &r.name
+                                })
+                            });
+                            match (l_is_left, l_is_right, r_is_left, r_is_right) {
+                                (true, _, _, true) => (Ok(l), Ok(r)),
+                                (_, true, true, _) => (Ok(r), Ok(l)),
+                                (_, _, _, _) => (
+                                    Err(DataFusionError::Plan(format!(

Review comment:
       Yes, I was leaving this until an initial review to understand if this was completely in the wrong direction. I can add further conditions and appropriate messages.




-- 
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