andygrove commented on code in PR #2702:
URL: https://github.com/apache/arrow-datafusion/pull/2702#discussion_r890326016
##########
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:
```suggestion
Some(filter_expr) => filters = Some(and(expr,
filter_expr)),
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]