Skip to content

Commit

Permalink
Add test eliminate_cross_not_possible_nested_inner_join_with_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
epsio-banay committed Sep 12, 2023
1 parent 2a39399 commit 542c10d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions datafusion/optimizer/src/eliminate_cross_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ mod tests {
assert_eq!(plan.schema(), optimized_plan.schema())
}

fn assert_optimization_rule_fails(plan: &LogicalPlan) {
let rule = EliminateCrossJoin::new();
let optimized_plan = rule.try_optimize(plan, &OptimizerContext::new()).unwrap();
assert!(optimized_plan.is_none());
}

#[test]
fn eliminate_cross_with_simple_and() -> Result<()> {
let t1 = test_table_scan_with_name("t1")?;
Expand Down Expand Up @@ -544,6 +550,30 @@ mod tests {
Ok(())
}

#[test]
/// See https://github.com/apache/arrow-datafusion/issues/7530
fn eliminate_cross_not_possible_nested_inner_join_with_filter() -> Result<()> {
let t1 = test_table_scan_with_name("t1")?;
let t2 = test_table_scan_with_name("t2")?;
let t3 = test_table_scan_with_name("t3")?;

// could not eliminate to inner join with filter
let plan = LogicalPlanBuilder::from(t1)
.join(
t3,
JoinType::Inner,
(vec!["t1.a"], vec!["t2.a"]),
Some(col("t1.a").not_eq(col("t2.a"))),
)?
.join(t2, JoinType::Inner, (vec!["t1.a"], vec!["t3.a"]), None)?
.filter(col("t1.a").lt(lit(15u32)))?
.build()?;

assert_optimization_rule_fails(&plan);

Ok(())
}

#[test]
/// ```txt
/// filter: a.id = b.id and a.id = c.id
Expand Down

0 comments on commit 542c10d

Please sign in to comment.