This is an automated email from the ASF dual-hosted git repository. liyafan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git
commit 2376a3a743d2ece3f81aee881b2fc381803def47 Author: NobiGo <[email protected]> AuthorDate: Wed Feb 16 14:41:03 2022 +0800 [CALCITE-4912] Confusing javadoc of RexSimplify.simplify --- core/src/main/java/org/apache/calcite/rex/RexSimplify.java | 4 ++-- core/src/test/java/org/apache/calcite/rex/RexProgramTest.java | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java index 7c0aa6b..8dd53a9 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java +++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java @@ -204,8 +204,8 @@ public class RexSimplify { * * <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> diff --git a/core/src/test/java/org/apache/calcite/rex/RexProgramTest.java b/core/src/test/java/org/apache/calcite/rex/RexProgramTest.java index 691c954..7f68dec 100644 --- a/core/src/test/java/org/apache/calcite/rex/RexProgramTest.java +++ b/core/src/test/java/org/apache/calcite/rex/RexProgramTest.java @@ -1003,6 +1003,10 @@ class RexProgramTest extends RexProgramTestBase { "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"); @@ -1130,7 +1134,7 @@ class RexProgramTest extends RexProgramTestBase { // 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, @@ -1142,7 +1146,7 @@ class RexProgramTest extends RexProgramTestBase { 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,
