ygf11 commented on code in PR #4866:
URL: https://github.com/apache/arrow-datafusion/pull/4866#discussion_r1066630859
##########
datafusion/optimizer/src/eliminate_cross_join.rs:
##########
@@ -176,159 +178,138 @@ fn flatten_join_inputs(
fn find_inner_join(
left_input: &LogicalPlan,
rights: &mut Vec<LogicalPlan>,
- possible_join_keys: &mut Vec<(Expr, Expr)>,
- all_join_keys: &mut HashSet<(Expr, Expr)>,
+ possible_join_predicates: &mut Vec<Expr>,
) -> Result<LogicalPlan> {
+ let mut candidate_right_input: Option<(usize, Vec<Expr>)> = None;
for (i, right_input) in rights.iter().enumerate() {
- let mut join_keys = vec![];
-
- for (l, r) in &mut *possible_join_keys {
- let key_pair = find_valid_equijoin_key_pair(
- l,
- r,
- left_input.schema().clone(),
- right_input.schema().clone(),
- )?;
+ let predicate_schemas =
+ [left_input.schema().clone(), right_input.schema().clone()];
+
+ // equijoin_flag indicct if join_predicates contains equijoin expr.
+ let (join_predicates, equijoin_flag): (Vec<Expr>, bool) =
+ possible_join_predicates.iter().try_fold(
+ (Vec::<Expr>::new(), false),
+ |(mut join_filters, mut equijoin_flag), expr| {
+ let is_join_filter =
+ is_valid_join_predicate(expr, &predicate_schemas)?;
+ if is_join_filter {
+ join_filters.push(expr.clone());
+ }
Review Comment:
@jackwener, this `try_fold` will filter join filters.
Suppose the `possible_join_predicates`:
* t1.a > 10
* t1.c = t2.c
* t3.b > t2.b
for t1 join t2, the `try_fold` will return `t1.a > 1` and `t1.c = t2.c`,
because all columns of these exprs are from `t1` and `t2`.
This logic is the same as you comment.
I will improve the code readability after the `CI` fix.
--
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]