This is an automated email from the ASF dual-hosted git repository.
kgyrtkirk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new 1e99937 [CALCITE-3215] Simplification may have not fully simplified
IS NOT NULL expressions
1e99937 is described below
commit 1e999374f3a40c26d1cb3469211f10cd2fdc0622
Author: Zoltan Haindrich <[email protected]>
AuthorDate: Fri Jul 26 10:42:52 2019 +0200
[CALCITE-3215] Simplification may have not fully simplified IS NOT NULL
expressions
The expression "(-x) is not null" should be simplified to "true" if x is
known to be not null.
---
.../java/org/apache/calcite/rex/RexSimplify.java | 14 +++++++++++++
.../org/apache/calcite/test/RexProgramTest.java | 23 ++++++++++++++++++++++
.../calcite/test/fuzzer/RexProgramFuzzyTest.java | 2 +-
3 files changed, 38 insertions(+), 1 deletion(-)
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 bbf6b28..07f0846 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
@@ -1023,6 +1023,8 @@ public class RexSimplify {
Set<SqlKind> safeOps = EnumSet.noneOf(SqlKind.class);
safeOps.addAll(SqlKind.COMPARISON);
+ safeOps.add(SqlKind.PLUS_PREFIX);
+ safeOps.add(SqlKind.MINUS_PREFIX);
safeOps.add(SqlKind.PLUS);
safeOps.add(SqlKind.MINUS);
safeOps.add(SqlKind.TIMES);
@@ -1032,6 +1034,8 @@ public class RexSimplify {
safeOps.add(SqlKind.IS_NOT_TRUE);
safeOps.add(SqlKind.IS_NULL);
safeOps.add(SqlKind.IS_NOT_NULL);
+ safeOps.add(SqlKind.IS_DISTINCT_FROM);
+ safeOps.add(SqlKind.IS_NOT_DISTINCT_FROM);
safeOps.add(SqlKind.IN);
safeOps.add(SqlKind.NOT_IN);
safeOps.add(SqlKind.OR);
@@ -1040,6 +1044,16 @@ public class RexSimplify {
safeOps.add(SqlKind.CASE);
safeOps.add(SqlKind.LIKE);
safeOps.add(SqlKind.COALESCE);
+ safeOps.add(SqlKind.TRIM);
+ safeOps.add(SqlKind.LTRIM);
+ safeOps.add(SqlKind.RTRIM);
+ safeOps.add(SqlKind.BETWEEN);
+ safeOps.add(SqlKind.CEIL);
+ safeOps.add(SqlKind.FLOOR);
+ safeOps.add(SqlKind.REVERSE);
+ safeOps.add(SqlKind.TIMESTAMP_ADD);
+ safeOps.add(SqlKind.TIMESTAMP_DIFF);
+ safeOps.add(SqlKind.LIKE);
this.safeOps = Sets.immutableEnumSet(safeOps);
}
diff --git a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
index e75c5e1..2be216d 100644
--- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
@@ -2716,6 +2716,29 @@ public class RexProgramTest extends
RexProgramBuilderBase {
lt(vIntNotNull(), literal(3)),
vBoolNotNull(2))));
}
+
+ @Test public void testIsNullSimplificationWithUnaryPlus() {
+ RexNode expr =
+ isNotNull(coalesce(unaryPlus(vInt(1)), vIntNotNull(0)));
+ RexNode s = simplify.simplifyUnknownAs(expr, RexUnknownAs.UNKNOWN);
+
+ assertThat(expr.isAlwaysTrue(), is(true));
+ assertThat(s, is(trueLiteral));
+ }
+
+ @Test public void testIsNullSimplificationWithIsDistinctFrom() {
+ RexNode expr =
+ isNotNull(
+ case_(
+ vBool(),
+ isDistinctFrom(falseLiteral, vBoolNotNull(0)),
+ vBoolNotNull(2))
+ );
+ RexNode s = simplify.simplifyUnknownAs(expr, RexUnknownAs.UNKNOWN);
+
+ assertThat(expr.isAlwaysTrue(), is(true));
+ assertThat(s, is(trueLiteral));
+ }
}
// End RexProgramTest.java
diff --git
a/core/src/test/java/org/apache/calcite/test/fuzzer/RexProgramFuzzyTest.java
b/core/src/test/java/org/apache/calcite/test/fuzzer/RexProgramFuzzyTest.java
index 885ecf6..3e4807f 100644
--- a/core/src/test/java/org/apache/calcite/test/fuzzer/RexProgramFuzzyTest.java
+++ b/core/src/test/java/org/apache/calcite/test/fuzzer/RexProgramFuzzyTest.java
@@ -65,7 +65,7 @@ public class RexProgramFuzzyTest extends
RexProgramBuilderBase {
private static final Duration TEST_DURATION =
Duration.of(Integer.getInteger("rex.fuzzing.duration", 5),
ChronoUnit.SECONDS);
- private static final long TEST_ITERATIONS =
Long.getLong("rex.fuzzing.iterations", 18);
+ private static final long TEST_ITERATIONS =
Long.getLong("rex.fuzzing.iterations", 2000);
// Stop fuzzing after detecting MAX_FAILURES errors
private static final int MAX_FAILURES =
Integer.getInteger("rex.fuzzing.max.failures", 1);