Skip to content

Commit

Permalink
[CALCITE-4912] Confusing javadoc of RexSimplify.simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
NobiGo authored and liyafan82 committed Mar 4, 2022
1 parent 1f660d5 commit 2376a3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/apache/calcite/rex/RexSimplify.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ public RexNode simplifyPreservingType(RexNode e, RexUnknownAs unknownAs,
*
* <p>In particular:</p>
* <ul>
* <li>{@code simplify(x = 1 AND y = 2 AND NOT x = 1)}
* returns {@code y = 2}</li>
* <li>{@code simplify(x = 1 OR NOT x = 1 OR x IS NULL)}
* returns {@code TRUE}</li>
* <li>{@code simplify(x = 1 AND FALSE)}
* returns {@code FALSE}</li>
* </ul>
Expand Down
8 changes: 6 additions & 2 deletions core/src/test/java/org/apache/calcite/rex/RexProgramTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,10 @@ private void checkExponentialCnf(int n) {
"false", "IS NULL(?0.i)");
checkSimplifyUnchanged(gt(iRef, hRef));

// "x = 1 or not x = 1 or x is null" simplifies to "true"
checkSimplify(or(eq(hRef, literal(1)), not(eq(hRef, literal(1))), isNull(hRef)), "true");
checkSimplify(or(eq(iRef, literal(1)), not(eq(iRef, literal(1))), isNull(iRef)), "true");

// "(not x) is null" to "x is null"
checkSimplify(isNull(not(vBool())), "IS NULL(?0.bool0)");
checkSimplify(isNull(not(vBoolNotNull())), "false");
Expand Down Expand Up @@ -1130,7 +1134,7 @@ private void checkExponentialCnf(int n) {
// condition with null value for range
checkSimplifyFilter(and(gt(aRef, nullBool), ge(bRef, literal(1))), "false");

// condition "1 < a && 5 < x" yields "5 < x"
// condition "1 < a && 5 < a" yields "5 < a"
checkSimplifyFilter(
and(lt(literal(1), aRef), lt(literal(5), aRef)),
RelOptPredicateList.EMPTY,
Expand All @@ -1142,7 +1146,7 @@ private void checkExponentialCnf(int n) {
RelOptPredicateList.EMPTY,
"SEARCH(?0.a, Sarg[(1..5)])");

// condition "1 > a && 5 > x" yields "1 > a"
// condition "1 > a && 5 > a" yields "1 > a"
checkSimplifyFilter(
and(gt(literal(1), aRef), gt(literal(5), aRef)),
RelOptPredicateList.EMPTY,
Expand Down

0 comments on commit 2376a3a

Please sign in to comment.