Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
cnf_rewrite in datafusion_optimizer::utils - Rust
[go: Go Back, main page]

pub fn cnf_rewrite(expr: Expr) -> Expr
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));