You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jc...@apache.org on 2018/10/17 20:44:23 UTC

calcite git commit: [CALCITE-2620] Simplify "coalesce(null, x)" to "x" (pengzhiwei)

Repository: calcite
Updated Branches:
  refs/heads/master b470a0cd4 -> 5b16e23df


[CALCITE-2620] Simplify "coalesce(null,x)" to "x" (pengzhiwei)

Close apache/calcite#882


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

Branch: refs/heads/master
Commit: 5b16e23dff03e5eaed80642ae91e28ebf806e6b0
Parents: b470a0c
Author: pengzhiwei <pe...@icloud.com>
Authored: Thu Oct 11 16:30:14 2018 +0800
Committer: Jesus Camacho Rodriguez <jc...@apache.org>
Committed: Wed Oct 17 13:43:34 2018 -0700

----------------------------------------------------------------------
 core/src/main/java/org/apache/calcite/rex/RexSimplify.java   | 3 ++-
 .../test/java/org/apache/calcite/test/RexProgramTest.java    | 8 ++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/5b16e23d/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 0f05980..c90c239 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexSimplify.java
@@ -653,7 +653,8 @@ public class RexSimplify {
     final List<RexNode> operands = new ArrayList<>();
     for (RexNode operand : call.getOperands()) {
       operand = simplify(operand, UNKNOWN);
-      if (digests.add(operand.toString())) {
+      if (!RexUtil.isNull(operand)
+          && digests.add(operand.toString())) {
         operands.add(operand);
       }
       if (!operand.getType().isNullable()) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/5b16e23d/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 dbd1e24..05ef9fb 100644
--- a/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RexProgramTest.java
@@ -2274,11 +2274,15 @@ public class RexProgramTest extends RexProgramBuilderBase {
             vIntNotNull()),
         "COALESCE(?0.int0, +(?0.int0, ?0.notNullInt0), 1)");
     checkSimplify2(coalesce(gt(nullInt, nullInt), trueLiteral),
-        "COALESCE(null, true)", "COALESCE(null, true)");
+        "true", "true");
     checkSimplify2(coalesce(unaryPlus(nullInt), unaryPlus(vInt())),
-        "COALESCE(null, +(?0.int0))", "COALESCE(null, +(?0.int0))");
+        "+(?0.int0)", "+(?0.int0)");
     checkSimplify(coalesce(unaryPlus(vInt(1)), unaryPlus(vInt())),
         "COALESCE(+(?0.int1), +(?0.int0))");
+
+    checkSimplify(coalesce(nullInt, vInt()), "?0.int0");
+    checkSimplify(coalesce(vInt(), nullInt, vInt(1)),
+        "COALESCE(?0.int0, ?0.int1)");
   }
 
   @Test public void simplifyNull() {