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 2015/02/10 04:05:21 UTC

[3/3] incubator-calcite git commit: [CALCITE-583] Operator || mishandles ANY type (Sean Hsuan-Yi Chu)

[CALCITE-583] Operator || mishandles ANY type (Sean Hsuan-Yi Chu)

Enable the ReturnType DYADIC_STRING_SUM_PRECISION to accept ANY type, which facilitates `||` concat to accept ANY type. See [DRILL-2008].

Close apache/incubator-calcite#47


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

Branch: refs/heads/master
Commit: 8afdd01fb4cca79e5960fb682308e888e985cc4c
Parents: ed8a4a0
Author: Hsuan-Yi Chu <hs...@usc.edu>
Authored: Sat Jan 31 12:39:41 2015 -0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Feb 9 16:37:19 2015 -0800

----------------------------------------------------------------------
 .../apache/calcite/sql/type/ReturnTypes.java    | 30 +++++++++++++++-----
 .../calcite/sql/test/SqlOperatorBaseTest.java   |  1 +
 2 files changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8afdd01f/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java b/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
index 219cb99..d9fcdcd 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
@@ -541,14 +541,21 @@ public abstract class ReturnTypes {
             SqlOperatorBinding opBinding) {
           final RelDataType argType0 = opBinding.getOperandType(0);
           final RelDataType argType1 = opBinding.getOperandType(1);
-          if (!(SqlTypeUtil.inCharOrBinaryFamilies(argType0)
-              && SqlTypeUtil.inCharOrBinaryFamilies(argType1))) {
+
+          final boolean containsAnyType =
+              (argType0.getSqlTypeName() == SqlTypeName.ANY)
+                  || (argType1.getSqlTypeName() == SqlTypeName.ANY);
+
+          if (!containsAnyType
+              && !(SqlTypeUtil.inCharOrBinaryFamilies(argType0)
+                  && SqlTypeUtil.inCharOrBinaryFamilies(argType1))) {
             Util.pre(
                 SqlTypeUtil.sameNamedType(argType0, argType1),
                 "SqlTypeUtil.sameNamedType(argTypes[0], argTypes[1])");
           }
           SqlCollation pickedCollation = null;
-          if (SqlTypeUtil.inCharFamily(argType0)) {
+          if (!containsAnyType
+              && SqlTypeUtil.inCharFamily(argType0)) {
             if (!SqlTypeUtil.isCharTypeComparable(
                 opBinding.collectOperandTypes().subList(0, 2))) {
               throw opBinding.newError(
@@ -571,10 +578,19 @@ public abstract class ReturnTypes {
           }
 
           RelDataType ret;
-          ret =
-              opBinding.getTypeFactory().createSqlType(
-                  typeName,
-                  argType0.getPrecision() + argType1.getPrecision());
+          int typePrecision;
+          if (argType0.getPrecision()
+              == RelDataType.PRECISION_NOT_SPECIFIED
+                  && argType1.getPrecision()
+                      == RelDataType.PRECISION_NOT_SPECIFIED) {
+            typePrecision = RelDataType.PRECISION_NOT_SPECIFIED;
+          } else {
+            typePrecision =
+                argType0.getPrecision() + argType1.getPrecision();
+          }
+
+          ret = opBinding.getTypeFactory()
+              .createSqlType(typeName, typePrecision);
           if (null != pickedCollation) {
             RelDataType pickedType;
             if (argType0.getCollation().equals(

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/8afdd01f/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 ecacb2d..ba9372d 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
@@ -1843,6 +1843,7 @@ public abstract class SqlOperatorBaseTest {
         "fedf",
         "BINARY(2) NOT NULL");
     tester.checkNull("x'ff' || cast(null as varbinary)");
+    tester.checkNull(" cast(null as ANY) || cast(null as ANY) ");
   }
 
   @Test public void testDivideOperator() {