Function datafusion_optimizer::utils::cnf_rewrite
source · Expand description
Tries to convert an expression to conjunctive normal form (CNF).
Does not convert the expression if the total number of conjuncts
(exprs ANDed together) would exceed [MAX_CNF_REWRITE_CONJUNCTS
].
The following expression is in CNF:
(a OR b) AND (c OR d)
The following is not in CNF:
(a AND b) OR c
.
But could be rewrite to a CNF expression:
(a OR c) AND (b OR c)
.
Example
// (a=1 AND b=2)OR c = 3
let expr1 = col("a").eq(lit(1)).and(col("b").eq(lit(2)));
let expr2 = col("c").eq(lit(3));
let expr = expr1.or(expr2);
//(a=1 or c=3)AND(b=2 or c=3)
let expr1 = col("a").eq(lit(1)).or(col("c").eq(lit(3)));
let expr2 = col("b").eq(lit(2)).or(col("c").eq(lit(3)));
let expect = expr1.and(expr2);
assert_eq!(expect, cnf_rewrite(expr));