calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [1/5] incubator-calcite git commit: [CALCITE-280] BigDecimal underflow (Li Yang)
Date Tue, 07 Jul 2015 17:58:32 GMT
Repository: incubator-calcite
Updated Branches:
  refs/heads/master 8774a671f -> 03111d2b6


[CALCITE-280] BigDecimal underflow (Li Yang)

Fix by Li Yang, test case by Julian Hyde.


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

Branch: refs/heads/master
Commit: e39911ed78221b23a8837f00b806a251ee496401
Parents: 8774a67
Author: Julian Hyde <jhyde@apache.org>
Authored: Mon Jul 6 20:44:46 2015 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Mon Jul 6 20:44:46 2015 -0700

----------------------------------------------------------------------
 .../java/org/apache/calcite/runtime/SqlFunctions.java  |  4 +++-
 core/src/test/resources/sql/agg.oq                     | 13 +++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/e39911ed/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index 256d15a..652fb85 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -544,7 +544,9 @@ public class SqlFunctions {
 
   /** SQL <code>/</code> operator applied to BigDecimal values. */
   public static BigDecimal divide(BigDecimal b0, BigDecimal b1) {
-    return (b0 == null || b1 == null) ? null : b0.divide(b1);
+    return (b0 == null || b1 == null)
+        ? null
+        : b0.divide(b1, MathContext.DECIMAL64);
   }
 
   // *

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/e39911ed/core/src/test/resources/sql/agg.oq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/agg.oq b/core/src/test/resources/sql/agg.oq
index 802f1dc..d81fa9e 100644
--- a/core/src/test/resources/sql/agg.oq
+++ b/core/src/test/resources/sql/agg.oq
@@ -760,6 +760,19 @@ from "scott".emp;
 
 !ok
 
+# [CALCITE-280] BigDecimal underflow
+# Previously threw "java.lang.ArithmeticException: Non-terminating decimal
+# expansion; no exact representable decimal result"
+select avg(comm) as a, count(comm) as c from "scott".emp where empno < 7844;
++-------------------+---+
+| A                 | C |
++-------------------+---+
+| 733.3333333333333 | 3 |
++-------------------+---+
+(1 row)
+
+!ok
+
 # [CALCITE-729] IndexOutOfBoundsException in ROLLUP query on JDBC data source
 !use jdbc_scott
 select deptno, job, count(*) as c


Mime
View raw message