Skip to content

SimplifyExpressions will fail when rebuild equijoin with alias #4754

Closed

Description

@ygf11

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

After #4666, LogicalPlan::expressions() and from_plan will combine and rebuild the equijoin keys.
But the from_plan may fail when the SimplifyExpressions rule gives the expression an alias.

For example,a test case with SimplifyExpressions rule:

#[test]
fn simplify_equijoin_predicate() -> Result<()> {
    let t1 = test_table_scan_with_name("t1")?;
    let t2 = test_table_scan_with_name("t2")?;

    let left_key = col("t1.a") + lit(1i64).cast_to(&DataType::UInt32, t1.schema())?;
    let right_key = col("t2.a") + lit(2i64).cast_to(&DataType::UInt32, t2.schema())?;
    let plan = LogicalPlanBuilder::from(t1)
        .join_with_expr_keys(
            t2,
            JoinType::Inner,
            (vec![left_key], vec![right_key]),
            None,
        )?
        .build()?;

    // before simplify: t1.a + CAST(Int64(1), UInt32) = t2.a + CAST(Int64(2), UInt32)
    // after simplify: t1.a + UInt32(1) = t2.a + UInt32(2) AS t1.a + Int64(1) = t2.a + Int64(2)
    let rule = SimplifyExpressions::new();
    let _ = rule
        .try_optimize(&plan, &OptimizerContext::new())
        // this result is a Error
        .unwrap()
        .expect("failed to optimize plan");
    .....
    Ok(())
}

Describe the solution you'd like
Add alias check for the given expression in from_plan.

Describe alternatives you've considered

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions