xuzifu666 commented on code in PR #5295:
URL: https://github.com/apache/calcite/pull/5295#discussion_r4220229203


##########
core/src/test/java/org/apache/calcite/rex/RexProgramTest.java:
##########
@@ -2472,6 +2472,61 @@ private void checkExponentialCnf(int n) {
         "=(?0.notNullInt0, ?0.int1)");
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-5907";>[CALCITE-5907]
+   * Unexpected boolean expression simplification for And expression</a>. */
+  @Test void testSimplifyAndEqualityTrue() {
+    // "=(x, true)" simplifies to "x" only if x is BOOLEAN;
+    // otherwise the AND would get a non-BOOLEAN operand
+    //
+    // Paranoid mode throws from RexSimplify.verify for these non-BOOLEAN
+    // inputs, so turn it off to let checkSimplifyUnchanged report the
+    // simplified expression instead
+    simplify = this.simplify.withParanoid(false);
+    checkSimplifyUnchanged(
+        and(eq(vVarchar(0), trueLiteral),
+            eq(vVarchar(1), trueLiteral)));
+    checkSimplifyUnchanged(
+        and(eq(vInt(0), trueLiteral),
+            eq(vInt(1), trueLiteral)));
+    // same, with NOT NULL variables
+    checkSimplifyUnchanged(
+        and(eq(vVarcharNotNull(0), trueLiteral),
+            eq(vVarcharNotNull(1), trueLiteral)));
+    checkSimplifyUnchanged(
+        and(eq(vIntNotNull(0), trueLiteral),
+            eq(vIntNotNull(1), trueLiteral)));
+    // literal on the left (swapped) form
+    checkSimplifyUnchanged(eq(trueLiteral, vVarchar(0)));
+    checkSimplifyUnchanged(
+        and(eq(trueLiteral, vVarchar(0)),
+            eq(trueLiteral, vVarchar(1))));
+    checkSimplifyUnchanged(
+        and(eq(falseLiteral, vVarchar(0)),
+            eq(falseLiteral, vVarchar(1))));
+    checkSimplifyUnchanged(
+        and(ne(falseLiteral, vVarchar(0)),
+            ne(falseLiteral, vVarchar(1))));
+    // "=$0, true" where $0 has type ANY is no longer simplified to "$0";
+    // ITEM on a MAP<VARCHAR, ANY> column (e.g. MongoDB's _MAP) produces ANY,
+    // which may be BOOLEAN at runtime

Review Comment:
   Done.



-- 
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]

Reply via email to