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 2016/09/29 07:39:16 UTC

calcite git commit: [CALCITE-1396] isDeterministic only explores top RexCall

Repository: calcite
Updated Branches:
  refs/heads/master 14ac78229 -> ddd70fa9e


[CALCITE-1396] isDeterministic only explores top RexCall


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

Branch: refs/heads/master
Commit: ddd70fa9ea214ce284c8cb41c38e6bea1c3bfa5f
Parents: 14ac782
Author: Jesus Camacho Rodriguez <jc...@apache.org>
Authored: Wed Sep 28 16:13:50 2016 +0100
Committer: Jesus Camacho Rodriguez <jc...@apache.org>
Committed: Thu Sep 29 08:38:28 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/calcite/rex/RexUtil.java    |  2 +-
 .../org/apache/calcite/rex/RexExecutorTest.java | 58 ++++++++++++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/ddd70fa9/core/src/main/java/org/apache/calcite/rex/RexUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexUtil.java b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
index cbb8985..d2a95fa 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexUtil.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexUtil.java
@@ -380,7 +380,7 @@ public class RexUtil {
               if (!call.getOperator().isDeterministic()) {
                 throw Util.FoundOne.NULL;
               }
-              return null;
+              return super.visitCall(call);
             }
           };
       e.accept(visitor);

http://git-wip-us.apache.org/repos/asf/calcite/blob/ddd70fa9/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java b/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
index 72a36e2..8f63e25 100644
--- a/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
+++ b/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
@@ -26,7 +26,13 @@ import org.apache.calcite.rel.type.RelDataTypeFactory;
 import org.apache.calcite.schema.SchemaPlus;
 import org.apache.calcite.schema.Schemas;
 import org.apache.calcite.server.CalciteServerStatement;
+import org.apache.calcite.sql.SqlBinaryOperator;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.fun.SqlMonotonicBinaryOperator;
 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.type.InferTypes;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.tools.Frameworks;
 import org.apache.calcite.util.NlsString;
@@ -213,6 +219,58 @@ public class RexExecutorTest {
     });
   }
 
+  @Test public void testDeterministic1() throws Exception {
+    check(new Action() {
+      public void check(RexBuilder rexBuilder, RexExecutorImpl executor) {
+        final RexNode plus =
+            rexBuilder.makeCall(SqlStdOperatorTable.PLUS,
+                rexBuilder.makeExactLiteral(BigDecimal.ONE),
+                rexBuilder.makeExactLiteral(BigDecimal.ONE));
+        assertThat(RexUtil.isDeterministic(plus), equalTo(true));
+      }
+    });
+  }
+
+  @Test public void testDeterministic2() throws Exception {
+    check(new Action() {
+      public void check(RexBuilder rexBuilder, RexExecutorImpl executor) {
+        final RexNode plus =
+            rexBuilder.makeCall(PLUS_RANDOM,
+                rexBuilder.makeExactLiteral(BigDecimal.ONE),
+                rexBuilder.makeExactLiteral(BigDecimal.ONE));
+        assertThat(RexUtil.isDeterministic(plus), equalTo(false));
+      }
+    });
+  }
+
+  @Test public void testDeterministic3() throws Exception {
+    check(new Action() {
+      public void check(RexBuilder rexBuilder, RexExecutorImpl executor) {
+        final RexNode plus =
+            rexBuilder.makeCall(SqlStdOperatorTable.PLUS,
+                rexBuilder.makeCall(PLUS_RANDOM,
+                    rexBuilder.makeExactLiteral(BigDecimal.ONE),
+                    rexBuilder.makeExactLiteral(BigDecimal.ONE)),
+                rexBuilder.makeExactLiteral(BigDecimal.ONE));
+        assertThat(RexUtil.isDeterministic(plus), equalTo(false));
+      }
+    });
+  }
+
+  private static final SqlBinaryOperator PLUS_RANDOM =
+      new SqlMonotonicBinaryOperator(
+          "+",
+          SqlKind.PLUS,
+          40,
+          true,
+          ReturnTypes.NULLABLE_SUM,
+          InferTypes.FIRST_KNOWN,
+          OperandTypes.PLUS_OPERATOR) {
+        @Override public boolean isDeterministic() {
+          return false;
+        }
+      };
+
   /** Test case for
    * <a href="https://issues.apache.org/jira/browse/CALCITE-1009">[CALCITE-1009]
    * SelfPopulatingList is not thread-safe</a>. */