calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject calcite git commit: [CALCITE-1486] Invalid "Invalid literal" error for complex expression
Date Sat, 12 Nov 2016 01:58:59 GMT
Repository: calcite
Updated Branches:
  refs/heads/master f36584ab7 -> b7e99bca9


[CALCITE-1486] Invalid "Invalid literal" error for complex expression


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

Branch: refs/heads/master
Commit: b7e99bca93b6601a7e28ae0f3100031a75f67a92
Parents: f36584a
Author: Julian Hyde <jhyde@apache.org>
Authored: Fri Nov 11 01:19:37 2016 -0800
Committer: Julian Hyde <jhyde@apache.org>
Committed: Fri Nov 11 01:19:37 2016 -0800

----------------------------------------------------------------------
 .../main/java/org/apache/calcite/sql/SqlCallBinding.java |  8 ++++++--
 .../src/main/java/org/apache/calcite/sql/SqlLiteral.java |  7 ++++---
 core/src/test/resources/sql/misc.iq                      | 11 +++++++++++
 3 files changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/b7e99bca/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
index 24c3f4c..ae8abae 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlCallBinding.java
@@ -215,8 +215,12 @@ public class SqlCallBinding extends SqlOperatorBinding {
   }
 
   @Override public Comparable getOperandLiteralValue(int ordinal) {
-    SqlNode node = call.operand(ordinal);
-    return SqlLiteral.value(node);
+    try {
+      final SqlNode node = call.operand(ordinal);
+      return SqlLiteral.value(node);
+    } catch (IllegalArgumentException e) {
+      return null;
+    }
   }
 
   @Override public boolean isOperandNull(int ordinal, boolean allowCast) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/b7e99bca/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java b/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java
index 8121e20..3f29975 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlLiteral.java
@@ -299,10 +299,11 @@ public class SqlLiteral extends SqlNode {
    * <li>If the node is INTERVAL_YEAR_MONTH_ in {@link SqlTypeFamily},
    * returns its sign multiplied by its months equivalent value
    *
-   * <li>Otherwise the behavior is not specified.
+   * <li>Otherwise throws {@link IllegalArgumentException}.
    * </ul>
    */
-  public static Comparable value(SqlNode node) {
+  public static Comparable value(SqlNode node)
+      throws IllegalArgumentException {
     if (node instanceof SqlLiteral) {
       final SqlLiteral literal = (SqlLiteral) node;
       if (literal.getTypeName() == SqlTypeName.SYMBOL) {
@@ -347,7 +348,7 @@ public class SqlLiteral extends SqlNode {
       }
       // fall through
     default:
-      throw Util.newInternal("invalid literal: " + node);
+      throw new IllegalArgumentException("not a literal: " + node);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/b7e99bca/core/src/test/resources/sql/misc.iq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/misc.iq b/core/src/test/resources/sql/misc.iq
index 3874d69..a93d7df 100644
--- a/core/src/test/resources/sql/misc.iq
+++ b/core/src/test/resources/sql/misc.iq
@@ -1195,6 +1195,17 @@ from "scott".dept;
 
 !ok
 
+# [CALCITE-1486] Invalid "Invalid literal" error for complex expression
+select 8388608/(60+27.39);
++-------------------+
+| EXPR$0            |
++-------------------+
+| 95990.47945989244 |
++-------------------+
+(1 row)
+
+!ok
+
 # [CALCITE-1120] Support SELECT without FROM
 select 2 + 2;
 +--------+


Mime
View raw message