You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2017/01/26 23:06:39 UTC

[1/3] calcite git commit: [CALCITE-1595] RelBuilder.call throws NullPointerException if argument types are invalid (Jess Balint)

Repository: calcite
Updated Branches:
  refs/heads/master bc40bc06a -> 7605d4218


[CALCITE-1595] RelBuilder.call throws NullPointerException if argument types are invalid (Jess Balint)

Now, both versions of RelBuilder.call() use the same type validation;
previously the Iterable variant bypassed validation.

Close apache/calcite#363


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

Branch: refs/heads/master
Commit: a55e5eb4b3ca9f1afa6e9dbeef466fa78f66812f
Parents: bc40bc0
Author: Jess Balint <jb...@gmail.com>
Authored: Thu Jan 26 11:21:53 2017 -0600
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Jan 26 11:22:48 2017 -0800

----------------------------------------------------------------------
 .../org/apache/calcite/tools/RelBuilder.java    |  9 ++++---
 .../org/apache/calcite/test/RelBuilderTest.java | 25 ++++++++++++++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/a55e5eb4/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
index 02d04dc..2b3a545 100644
--- a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
+++ b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
@@ -513,8 +513,12 @@ public class RelBuilder {
 
   /** Creates a call to a scalar operator. */
   public RexNode call(SqlOperator operator, RexNode... operands) {
+    return call(operator, ImmutableList.copyOf(operands));
+  }
+
+  /** Creates a call to a scalar operator. */
+  private RexNode call(SqlOperator operator, List<RexNode> operandList) {
     final RexBuilder builder = cluster.getRexBuilder();
-    final List<RexNode> operandList = ImmutableList.copyOf(operands);
     final RelDataType type = builder.deriveReturnType(operator, operandList);
     if (type == null) {
       throw new IllegalArgumentException("cannot derive type: " + operator
@@ -526,8 +530,7 @@ public class RelBuilder {
   /** Creates a call to a scalar operator. */
   public RexNode call(SqlOperator operator,
       Iterable<? extends RexNode> operands) {
-    return cluster.getRexBuilder().makeCall(operator,
-        ImmutableList.copyOf(operands));
+    return call(operator, ImmutableList.copyOf(operands));
   }
 
   /** Creates an AND. */

http://git-wip-us.apache.org/repos/asf/calcite/blob/a55e5eb4/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
index 533dad4..cabbcdc 100644
--- a/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelBuilderTest.java
@@ -1613,6 +1613,31 @@ public class RelBuilderTest {
       assertThat(s, is(result));
     }
   }
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-1595">[CALCITE-1595]
+   * RelBuilder.call throws NullPointerException if argument types are
+   * invalid</a>. */
+  @Test public void testTypeInferenceValidation() throws Exception {
+    final RelBuilder builder = RelBuilder.create(config().build());
+    // test for a) call(operator, Iterable<RexNode>)
+    final RexNode arg0 = builder.literal(0);
+    final RexNode arg1 = builder.literal("xyz");
+    try {
+      builder.call(SqlStdOperatorTable.PLUS, Lists.newArrayList(arg0, arg1));
+      fail("Invalid combination of parameter types");
+    } catch (IllegalArgumentException e) {
+      assertThat(e.getMessage(), containsString("cannot derive type"));
+    }
+
+    // test for b) call(operator, RexNode...)
+    try {
+      builder.call(SqlStdOperatorTable.PLUS, arg0, arg1);
+      fail("Invalid combination of parameter types");
+    } catch (IllegalArgumentException e) {
+      assertThat(e.getMessage(), containsString("cannot derive type"));
+    }
+  }
 }
 
 // End RelBuilderTest.java


[3/3] calcite git commit: [CALCITE-1600] In Meta.Frame.create, change type of "offset" parameter from "int" to "long" (Gian Merlino)

Posted by jh...@apache.org.
[CALCITE-1600] In Meta.Frame.create, change type of "offset" parameter from "int" to "long" (Gian Merlino)

Close apache/calcite#351


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

Branch: refs/heads/master
Commit: 7605d42185ac627f33d14ffbb0e95d6ca4082659
Parents: ae12a5d
Author: Gian Merlino <gi...@gmail.com>
Authored: Sat Jan 14 09:38:35 2017 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Jan 26 12:23:13 2017 -0800

----------------------------------------------------------------------
 avatica/core/src/main/java/org/apache/calcite/avatica/Meta.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/7605d421/avatica/core/src/main/java/org/apache/calcite/avatica/Meta.java
----------------------------------------------------------------------
diff --git a/avatica/core/src/main/java/org/apache/calcite/avatica/Meta.java b/avatica/core/src/main/java/org/apache/calcite/avatica/Meta.java
index c2c6a39..7df9ade 100644
--- a/avatica/core/src/main/java/org/apache/calcite/avatica/Meta.java
+++ b/avatica/core/src/main/java/org/apache/calcite/avatica/Meta.java
@@ -909,7 +909,7 @@ public interface Meta {
     }
 
     @JsonCreator
-    public static Frame create(@JsonProperty("offset") int offset,
+    public static Frame create(@JsonProperty("offset") long offset,
         @JsonProperty("done") boolean done,
         @JsonProperty("rows") List<Object> rows) {
       if (offset == 0 && done && rows.isEmpty()) {


[2/3] calcite git commit: [CALCITE-1604] Add JDBC/ODBC scalar functions DATABASE, IFNULL, USER (Laurent Goujon)

Posted by jh...@apache.org.
[CALCITE-1604] Add JDBC/ODBC scalar functions DATABASE, IFNULL, USER (Laurent Goujon)

Close apache/calcite#362


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

Branch: refs/heads/master
Commit: ae12a5dcc47ad1afc9a023a2b498a328196afb44
Parents: a55e5eb
Author: Laurent Goujon <la...@dremio.com>
Authored: Wed Jan 25 15:51:34 2017 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Jan 26 12:22:32 2017 -0800

----------------------------------------------------------------------
 core/src/main/codegen/templates/Parser.jj       |  1 +
 .../calcite/adapter/enumerable/RexImpTable.java |  9 +++++---
 .../apache/calcite/sql/SqlJdbcFunctionCall.java | 22 +++++++++++++++++++-
 .../calcite/sql/test/SqlOperatorBaseTest.java   | 20 ++++++++++--------
 site/_docs/reference.md                         | 10 ++++-----
 5 files changed, 44 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/ae12a5dc/core/src/main/codegen/templates/Parser.jj
----------------------------------------------------------------------
diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj
index 979a707..6887a21 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -4759,6 +4759,7 @@ SqlIdentifier ReservedFunctionName() :
         | <STDDEV_SAMP>
         | <SUM>
         | <UPPER>
+        | <USER>
         | <VAR_POP>
         | <VAR_SAMP>
     )

http://git-wip-us.apache.org/repos/asf/calcite/blob/ae12a5dc/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
index eff8cc1..3d49c39 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
@@ -107,6 +107,7 @@ import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CONCAT;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.COS;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.COT;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.COUNT;
+import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CURRENT_CATALOG;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CURRENT_DATE;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CURRENT_PATH;
 import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CURRENT_ROLE;
@@ -391,6 +392,7 @@ public class RexImpTable {
     map.put(SYSTEM_USER, systemFunctionImplementor);
     map.put(CURRENT_PATH, systemFunctionImplementor);
     map.put(CURRENT_ROLE, systemFunctionImplementor);
+    map.put(CURRENT_CATALOG, systemFunctionImplementor);
 
     // Current time functions
     map.put(CURRENT_TIME, systemFunctionImplementor);
@@ -1994,9 +1996,10 @@ public class RexImpTable {
       } else if (op == SYSTEM_USER) {
         return Expressions.constant(System.getProperty("user.name"));
       } else if (op == CURRENT_PATH
-          || op == CURRENT_ROLE) {
-        // By default, the CURRENT_ROLE function returns
-        // the empty string because a role has to be set explicitly.
+          || op == CURRENT_ROLE
+          || op == CURRENT_CATALOG) {
+        // By default, the CURRENT_ROLE and CURRENT_CATALOG functions return the
+        // empty string because a role or a catalog has to be set explicitly.
         return Expressions.constant("");
       } else if (op == CURRENT_TIMESTAMP) {
         return Expressions.call(BuiltInMethod.CURRENT_TIMESTAMP.method, root);

http://git-wip-us.apache.org/repos/asf/calcite/blob/ae12a5dc/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java b/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java
index 71a7e47..34c42be 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlJdbcFunctionCall.java
@@ -434,6 +434,15 @@ public class SqlJdbcFunctionCall extends SqlFunction {
     return super.createCall(functionQualifier, pos, operands);
   }
 
+  @Override public SqlNode rewriteCall(SqlValidator validator,
+      SqlCall call) {
+    if (null == lookupMakeCallObj) {
+      throw validator.newValidationError(call,
+          RESOURCE.functionUndefined(getName()));
+    }
+    return lookupMakeCallObj.getOperator().rewriteCall(validator, call);
+  }
+
   public SqlCall getLookupCall() {
     if (null == lookupCall) {
       lookupCall =
@@ -543,7 +552,7 @@ public class SqlJdbcFunctionCall extends SqlFunction {
   private interface MakeCall {
     /**
      * Creates and return a {@link SqlCall}. If the MakeCall strategy object
-     * was created with a reording specified the call will be created with
+     * was created with a reordering specified the call will be created with
      * the operands reordered, otherwise no change of ordering is applied
      *
      * @param operands Operands
@@ -718,6 +727,17 @@ public class SqlJdbcFunctionCall extends SqlFunction {
       map.put("NOW", simple(SqlStdOperatorTable.CURRENT_TIMESTAMP));
       map.put("TIMESTAMPADD", simple(SqlStdOperatorTable.TIMESTAMP_ADD));
       map.put("TIMESTAMPDIFF", simple(SqlStdOperatorTable.TIMESTAMP_DIFF));
+
+      map.put("DATABASE", simple(SqlStdOperatorTable.CURRENT_CATALOG));
+      map.put("IFNULL",
+          new SimpleMakeCall(SqlStdOperatorTable.COALESCE) {
+            @Override public SqlCall createCall(SqlParserPos pos,
+                SqlNode... operands) {
+              assert 2 == operands.length;
+              return super.createCall(pos, operands);
+            }
+          });
+      map.put("USER", simple(SqlStdOperatorTable.CURRENT_USER));
       map.put("CONVERT",
           new SimpleMakeCall(SqlStdOperatorTable.CAST) {
             @Override public SqlCall createCall(SqlParserPos pos,

http://git-wip-us.apache.org/repos/asf/calcite/blob/ae12a5dc/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
index 71df5c5..24c33f5 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
@@ -1780,15 +1780,10 @@ public abstract class SqlOperatorBaseTest {
     }
 
     // System Functions
-    if (false) {
-      tester.checkScalar("{fn DATABASE()}", null, "");
-    }
-    if (false) {
-      tester.checkScalar("{fn IFNULL(expression, value)}", null, "");
-    }
-    if (false) {
-      tester.checkScalar("{fn USER()}", null, "");
-    }
+    tester.checkType("{fn DATABASE()}", "VARCHAR(2000) NOT NULL");
+    tester.checkString("{fn IFNULL('a', 'b')}", "a", "CHAR(1) NOT NULL");
+    tester.checkString("{fn USER()}", "sa", "VARCHAR(2000) NOT NULL");
+
 
     // Conversion Functions
     // Legacy JDBC style
@@ -4322,6 +4317,13 @@ public abstract class SqlOperatorBaseTest {
     tester.checkString("CURRENT_ROLE", "", "VARCHAR(2000) NOT NULL");
   }
 
+  @Test public void testCurrentCatalogFunc() {
+    tester.setFor(SqlStdOperatorTable.CURRENT_CATALOG, VM_FENNEL);
+    // By default, the CURRENT_CATALOG function returns
+    // the empty string because a catalog has to be set explicitly.
+    tester.checkString("CURRENT_CATALOG", "", "VARCHAR(2000) NOT NULL");
+  }
+
   @Test public void testLocalTimeFunc() {
     tester.setFor(SqlStdOperatorTable.LOCALTIME);
     tester.checkScalar("LOCALTIME", TIME_PATTERN, "TIME(0) NOT NULL");

http://git-wip-us.apache.org/repos/asf/calcite/blob/ae12a5dc/site/_docs/reference.md
----------------------------------------------------------------------
diff --git a/site/_docs/reference.md b/site/_docs/reference.md
index 50574da..3b9c3d3 100644
--- a/site/_docs/reference.md
+++ b/site/_docs/reference.md
@@ -1172,11 +1172,11 @@ Not implemented:
 
 #### System
 
-Not implemented:
-
-* {fn DATABASE()}
-* {fn IFNULL(value, value)}
-* {fn USER(value, value)}
+| Operator syntax | Description
+|:--------------- |:-----------
+| {fn DATABASE()} | Equivalent to `CURRENT_CATALOG`
+| {fn IFNULL(value1, value2)} | Returns value2 if value1 is null
+| {fn USER()}     | Equivalent to `CURRENT_USER`
 
 #### Conversion