korowa commented on code in PR #2591:
URL: https://github.com/apache/arrow-datafusion/pull/2591#discussion_r882081511


##########
datafusion/sql/src/planner.rs:
##########
@@ -572,95 +572,116 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                 // extract join keys
                 extract_join_keys(expr, &mut keys, &mut filter);
 
-                let mut cols = HashSet::new();
-                exprlist_to_columns(&filter, &mut cols)?;
-
                 let (left_keys, right_keys): (Vec<Column>, Vec<Column>) =
                     keys.into_iter().unzip();
 
-                // return the logical plan representing the join
+                let normalized_filters = filter
+                    .into_iter()
+                    .map(|expr| {
+                        let mut using_columns = HashSet::new();
+                        expr_to_columns(&expr, &mut using_columns)?;
+
+                        normalize_col_with_schemas(
+                            expr,
+                            &[left.schema(), right.schema()],
+                            &[using_columns],
+                        )
+                    })
+                    .collect::<Result<Vec<_>>>()?;
+
                 if left_keys.is_empty() {
                     // When we don't have join keys, use cross join
                     let join = 
LogicalPlanBuilder::from(left).cross_join(&right)?;
 
-                    join.filter(filter.into_iter().reduce(Expr::and).unwrap())?
+                    if normalized_filters.is_empty() {
+                        join.build()
+                    } else {
+                        join.filter(
+                            
normalized_filters.into_iter().reduce(Expr::and).unwrap(),
+                        )?
                         .build()
-                } else if filter.is_empty() {
+                    }
+                } else if join_type == JoinType::Inner && 
!normalized_filters.is_empty() {
                     let join = LogicalPlanBuilder::from(left).join(
                         &right,
                         join_type,
                         (left_keys, right_keys),
+                        None,
                     )?;
-                    join.build()
-                } else if join_type == JoinType::Inner {
+                    join.filter(
+                        
normalized_filters.into_iter().reduce(Expr::and).unwrap(),
+                    )?
+                    .build()
+                } else if join_type == JoinType::Left {
+                    // Inner filters - predicates based only on right input 
columns

Review Comment:
   There are tests on planner part below - [left 
join](https://github.com/apache/arrow-datafusion/blob/875d8bb8346190f397b07d3ee87c2f29ce67a934/datafusion/sql/src/planner.rs#L3832),
 [right 
join](https://github.com/apache/arrow-datafusion/blob/875d8bb8346190f397b07d3ee87c2f29ce67a934/datafusion/sql/src/planner.rs#L3846)



-- 
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-unsubscr...@arrow.apache.org

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

Reply via email to