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/06/07 01:55:00 UTC

[GitHub] [arrow-datafusion] AssHero commented on a diff in pull request #2702: Make sure that the data types are supported in hashjoin before genera…

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


##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -605,17 +606,52 @@ impl LogicalPlanBuilder {
         let on: Vec<(_, _)> = left_keys.into_iter().zip(right_keys.into_iter()).collect();
         let join_schema =
             build_join_schema(self.plan.schema(), right.schema(), &join_type)?;
-
-        Ok(Self::from(LogicalPlan::Join(Join {
-            left: Arc::new(self.plan.clone()),
-            right: Arc::new(right.clone()),
-            on,
-            filter: None,
-            join_type,
-            join_constraint: JoinConstraint::Using,
-            schema: DFSchemaRef::new(join_schema),
-            null_equals_null: false,
-        })))
+        let mut join_on: Vec<(Column, Column)> = vec![];
+        let mut filters: Option<Expr> = None;
+        for (l, r) in &on {
+            if self.plan.schema().field_from_column(l).is_ok()
+                && right.schema().field_from_column(r).is_ok()
+                && can_hash(self.plan.schema().field_from_column(l).unwrap().data_type())
+            {
+                join_on.push((l.clone(), r.clone()));
+            } else if self.plan.schema().field_from_column(r).is_ok()
+                && right.schema().field_from_column(l).is_ok()
+                && can_hash(self.plan.schema().field_from_column(r).unwrap().data_type())
+            {
+                join_on.push((r.clone(), l.clone()));
+            } else {
+                let expr = Expr::BinaryExpr {
+                    left: Box::new(Expr::Column(l.clone())),
+                    op: Operator::Eq,
+                    right: Box::new(Expr::Column(r.clone())),
+                };
+                match filters {
+                    None => filters = Some(expr),
+                    Some(filter_expr) => {
+                        filters = Some(Expr::BinaryExpr {
+                            left: Box::new(expr),
+                            op: Operator::And,
+                            right: Box::new(filter_expr),
+                        });
+                    }

Review Comment:
   Thank you! I'll fix this.



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