Repository: calcite
Updated Branches:
  refs/heads/master 3a4fba828 -> 999716535


[CALCITE-2506] RexSimplify: coalesce(unaryPlus(nullInt), unaryPlus(vInt())) 
results in AssertionError: result mismatch (pengzhiwei)

fixes #873


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/99971653
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/99971653
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/99971653

Branch: refs/heads/master
Commit: 999716535b53f8541907fa3269de11e3e6e374e8
Parents: 3a4fba8
Author: pengzhiwei <[email protected]>
Authored: Mon Oct 1 15:17:42 2018 +0800
Committer: Vladimir Sitnikov <[email protected]>
Committed: Mon Oct 1 12:58:06 2018 +0300

----------------------------------------------------------------------
 .../org/apache/calcite/rex/RexSimplify.java     |  2 +-
 .../org/apache/calcite/test/RexProgramTest.java | 34 +++++++++-----------
 2 files changed, 16 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/99971653/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
----------------------------------------------------------------------
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 02a1e51..8a67ab7 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
@@ -580,7 +580,7 @@ public class RexSimplify {
     final RexSimplify simplify = withUnknownAsFalse(false);
     for (RexNode operand : call.getOperands()) {
       operand = simplify.simplify_(operand);
-      if (digests.add(operand.digest)) {
+      if (digests.add(operand.toString())) {
         operands.add(operand);
       }
       if (!operand.getType().isNullable()) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/99971653/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
----------------------------------------------------------------------
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 6c1960a..07c5010 100644
--- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
@@ -56,7 +56,6 @@ import com.google.common.collect.LinkedHashMultimap;
 import com.google.common.collect.Multimap;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import java.math.BigDecimal;
@@ -1202,16 +1201,6 @@ public class RexProgramTest extends 
RexProgramBuilderBase {
     checkSimplify2(gt(iRef, iRef), ">(?0.i, ?0.i)", "false");
     checkSimplify(gt(iRef, hRef), ">(?0.i, ?0.h)");
 
-    checkSimplify(coalesce(hRef, iRef), "?0.h"); // first arg not null
-    checkSimplify(coalesce(iRef, hRef), "COALESCE(?0.i, ?0.h)"); // a0 nullable
-    checkSimplify(coalesce(iRef, iRef), "?0.i"); // repeated arg
-    checkSimplify(coalesce(hRef, hRef), "?0.h"); // repeated arg
-    checkSimplify(coalesce(hRef, literal1), "?0.h");
-    checkSimplify(coalesce(iRef, literal1), "COALESCE(?0.i, 1)");
-    checkSimplify(coalesce(iRef, plus(iRef, hRef), literal1, hRef),
-        "COALESCE(?0.i, +(?0.i, ?0.h), 1)");
-    checkSimplify2(coalesce(gt(nullInt, nullInt), trueLiteral),
-        "COALESCE(null, true)", "COALESCE(null, true)");
     // "(not x) is null" to "x is null"
     checkSimplify(isNull(not(vBool())), "IS NULL(?0.bool0)");
     checkSimplify(isNull(not(vBoolNotNull())), "false");
@@ -2161,14 +2150,21 @@ public class RexProgramTest extends 
RexProgramBuilderBase {
         "IS DISTINCT FROM(?0.bool0, ?0.bool1)");
   }
 
-  @Ignore("[CALCITE-2505] java.lang.AssertionError: result mismatch")
-  @Test public void coalescePlusNull() {
-    // when applied to {?0.int0=-1},
-    // COALESCE(+(null), +(?0.int0)) yielded -1,
-    // and +(null) yielded NULL
-    checkSimplify2(
-        coalesce(unaryPlus(nullInt), unaryPlus(vInt())),
-        "...", "...");
+  @Test public void testSimplifyCoalesce() {
+    checkSimplify(coalesce(vIntNotNull(), vInt()), "?0.notNullInt0"); // first 
arg not null
+    checkSimplify(coalesce(vInt(), vIntNotNull()), "COALESCE(?0.int0, 
?0.notNullInt0)");
+    checkSimplify(coalesce(vInt(), vInt()), "?0.int0"); // repeated arg
+    checkSimplify(coalesce(vIntNotNull(), vIntNotNull()), "?0.notNullInt0"); 
// repeated arg
+    checkSimplify(coalesce(vIntNotNull(), literal(1)), "?0.notNullInt0");
+    checkSimplify(coalesce(vInt(), literal(1)), "COALESCE(?0.int0, 1)");
+    checkSimplify(coalesce(vInt(), plus(vInt(), vIntNotNull()), literal(1), 
vIntNotNull()),
+        "COALESCE(?0.int0, +(?0.int0, ?0.notNullInt0), 1)");
+    checkSimplify2(coalesce(gt(nullInt, nullInt), trueLiteral),
+        "COALESCE(null, true)", "COALESCE(null, true)");
+    checkSimplify2(coalesce(unaryPlus(nullInt), unaryPlus(vInt())),
+        "COALESCE(null, +(?0.int0))", "COALESCE(null, +(?0.int0))");
+    checkSimplify(coalesce(unaryPlus(vInt(1)), unaryPlus(vInt())),
+        "COALESCE(+(?0.int1), +(?0.int0))");
   }
 
   @Test

Reply via email to