Skip to content

Commit

Permalink
split ON expressions only by AND operator (apache#2534)
Browse files Browse the repository at this point in the history
  • Loading branch information
korowa authored and MazterQyou committed May 26, 2022
1 parent cd8e07e commit e5de24c
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions datafusion/core/src/sql/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2494,17 +2494,8 @@ fn extract_join_keys(
extract_join_keys(*right, accum, accum_filter);
}
}
_other
if matches!(**left, Expr::Column(_))
|| matches!(**right, Expr::Column(_)) =>
{
accum_filter.push(expr);
}
_other => {
if let Expr::BinaryExpr { left, op: _, right } = expr {
extract_join_keys(*left, accum, accum_filter);
extract_join_keys(*right, accum, accum_filter);
}
accum_filter.push(expr);
}
},
_other => {
Expand Down Expand Up @@ -4449,4 +4440,30 @@ mod tests {
\n EmptyRelation";
quick_test(sql, expected);
}

#[test]
fn join_on_disjunction_condition() {
let sql = "SELECT id, order_id \
FROM person \
JOIN orders ON id = customer_id OR person.age > 30";
let expected = "Projection: #person.id, #orders.order_id\
\n Filter: #person.id = #orders.customer_id OR #person.age > Int64(30)\
\n CrossJoin:\
\n TableScan: person projection=None\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

#[test]
fn join_on_complex_condition() {
let sql = "SELECT id, order_id \
FROM person \
JOIN orders ON id = customer_id AND (person.age > 30 OR person.last_name = 'X')";
let expected = "Projection: #person.id, #orders.order_id\
\n Filter: #person.age > Int64(30) OR #person.last_name = Utf8(\"X\")\
\n Inner Join: #person.id = #orders.customer_id\
\n TableScan: person projection=None\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}
}

0 comments on commit e5de24c

Please sign in to comment.