Skip to content

Should not fold a non-constant expression when it is not clear to do so #1244

@NGA-TRAN

Description

@NGA-TRAN

Describe the bug
This expression col < 10 and boolean(NULL) can either be NULL or false depending on the result of col < 10. Hence it should not be rewritten to a constant but it is current can.

To Reproduce
Add the following test in optimize_expr_bool_and, you will see it was rewritten to c1 BETWEEN Int32(0) AND Int32(10) which is wrong.

      // c1 BETWEEN Int32(0) AND Int32(10) AND Boolean(NULL)
      // it can be either NULL or false depending on the value of `c1 BETWEEN Int32(0) AND Int32(10`
       let expr = Expr::Between{ expr: Box::new(col("c1")), negated: false, low: Box::new(lit(0)), high: Box::new(lit(10))};
       let expr = expr.and(Expr::Literal(ScalarValue::Boolean(None)));
       let result = expr.clone().rewrite(&mut rewriter)?;
       println!("expr: {:#?} \n result: {:#?}", expr, result);
       assert_eq!(expr, result);

Expected behavior
Do not rewritten expression that does not have deterministic result yet

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions