Ted-Jiang commented on code in PR #3859:
URL: https://github.com/apache/arrow-datafusion/pull/3859#discussion_r998268672
##########
datafusion/optimizer/src/utils.rs:
##########
@@ -663,4 +796,84 @@ mod tests {
"mismatch rewriting expr_from: {expr_from} to {rewrite_to}"
)
}
+
+ #[test]
+ fn test_rewrite_cnf() {
+ let a_1 = col("a").eq(lit(1i64));
+ let a_2 = col("a").eq(lit(2i64));
+
+ let b_1 = col("b").eq(lit(1i64));
+ let b_2 = col("b").eq(lit(2i64));
+
+ // Test rewrite on a1_and_b2 and a2_and_b1 -> not change
+ let mut helper = CnfHelper::new();
+ let expr1 = and(a_1.clone(), b_2.clone());
+ let expect = expr1.clone();
+ let res = expr1.rewrite(&mut helper).unwrap();
+ assert_eq!(expect, res);
+
+ // Test rewrite on a1_and_b2 and a2_and_b1 -> (((a1 and b2) and a2)
and b1)
+ let mut helper = CnfHelper::new();
+ let expr1 = and(and(a_1.clone(), b_2.clone()), and(a_2.clone(),
b_1.clone()));
+ let expect = and(a_1.clone(), b_2.clone())
Review Comment:
We need improve the `Expr` fmt: like
```
let expr1 = and(a_1.clone(), b_2.clone())
.and(a_2.clone())
.and(b_1.clone());
let expr2 = and(and(a_1.clone(), b_2.clone()), and(a_2.clone(),
b_1.clone()));
assert_eq!(expr1, expr2);
```
This is not equal but they have the same string format:
```
a = Int64(1) AND b = Int64(2) AND a = Int64(2) AND b = Int64(1)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]