Repository: tajo
Updated Branches:
refs/heads/branch-0.8.1 f0ee8d59e -> 46c1cf564
TAJO-827: SUM() overflow in the case of INT4. (Hyoungjun Kim via hyunsik)
Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/46c1cf56
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/46c1cf56
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/46c1cf56
Branch: refs/heads/branch-0.8.1
Commit: 46c1cf564058891fb3681dc4183628888426f98f
Parents: f0ee8d5
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Wed May 21 12:23:39 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Wed May 21 12:35:32 2014 +0900
----------------------------------------------------------------------
CHANGES | 4 +++-
.../tajo/engine/function/builtin/SumInt.java | 10 ++++-----
.../tajo/engine/query/TestSelectQuery.java | 22 ++++++++++++++++++++
.../TestSelectQuery/testSumFloatOverflow.sql | 1 +
.../TestSelectQuery/testSumIntOverflow.sql | 1 +
.../TestSelectQuery/testSumFloatOverflow.result | 3 +++
.../TestSelectQuery/testSumIntOverflow.result | 3 +++
7 files changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tajo/blob/46c1cf56/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index a39d479..41a70db 100644
--- a/CHANGES
+++ b/CHANGES
@@ -18,7 +18,9 @@ Release 0.8.1 - unreleased
BUGS
- TAJO-821: IllegalStateException occurs when a NettyClientBase object is created
+ TAJO-827: SUM() overflow in the case of INT4. (Hyoungjun Kim via hyunsik)
+
+ TAJO-821: IllegalStateException occurs when a NettyClientBase object is created
within single thread. (hyoungjunkim via jinho)
TAJO-816: NULL delimiter doesn't apply with HCatalogStore. (jaehwa)
http://git-wip-us.apache.org/repos/asf/tajo/blob/46c1cf56/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/SumInt.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/SumInt.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/SumInt.java
index fff3a23..ce98128 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/SumInt.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/SumInt.java
@@ -39,7 +39,7 @@ import org.apache.tajo.storage.Tuple;
functionName = "sum",
description = "the sum of a set of numbers",
example = "> SELECT sum(expr);",
- returnType = Type.INT4,
+ returnType = Type.INT8,
paramTypes = {@ParamTypes(paramTypes = {Type.INT4})}
)
public class SumInt extends AggFunction<Datum> {
@@ -63,20 +63,20 @@ public class SumInt extends AggFunction<Datum> {
@Override
public Datum getPartialResult(FunctionContext ctx) {
- return DatumFactory.createInt4(((SumIntContext) ctx).sum);
+ return DatumFactory.createInt8(((SumIntContext) ctx).sum);
}
@Override
public DataType getPartialResultType() {
- return CatalogUtil.newSimpleDataType(Type.INT4);
+ return CatalogUtil.newSimpleDataType(Type.INT8);
}
@Override
public Datum terminate(FunctionContext ctx) {
- return DatumFactory.createInt4(((SumIntContext) ctx).sum);
+ return DatumFactory.createInt8(((SumIntContext) ctx).sum);
}
private class SumIntContext implements FunctionContext {
- int sum;
+ long sum;
}
}
http://git-wip-us.apache.org/repos/asf/tajo/blob/46c1cf56/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
index 37a748c..cec24a3 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
@@ -316,4 +316,26 @@ public class TestSelectQuery extends QueryTestCaseBase {
executeString("DROP DATABASE \"TestSelectQuery\"").close();
}
}
+
+ @Test
+ public final void testSumIntOverflow() throws Exception {
+ // Test data's min value is 17 and number of rows is 5.
+ // 25264513 = 2147483647/17/5
+ // result is 116,848,374,845 ==> int overflow
+ // select sum(cast(l_quantity * 25264513 as INT4)) from lineitem where l_quantity >
0;
+ ResultSet res = executeQuery();
+ assertResultSet(res);
+ cleanupQuery(res);
+ }
+
+ @Test
+ public final void testSumFloatOverflow() throws Exception {
+ // Test data's min value is 21168.23 and number of rows is 5.
+ // 3.21506374375027E33 = 3.40282346638529E38/21168/ 5
+ // result is 6.838452478692677E38 ==> float4 overflow
+ // select sum(cast(L_EXTENDEDPRICE * 3.21506374375027E33 as FLOAT4)) from lineitem where
l_quantity > 0;
+ ResultSet res = executeQuery();
+ assertResultSet(res);
+ cleanupQuery(res);
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tajo/blob/46c1cf56/tajo-core/src/test/resources/queries/TestSelectQuery/testSumFloatOverflow.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestSelectQuery/testSumFloatOverflow.sql
b/tajo-core/src/test/resources/queries/TestSelectQuery/testSumFloatOverflow.sql
new file mode 100644
index 0000000..9ec941a
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestSelectQuery/testSumFloatOverflow.sql
@@ -0,0 +1 @@
+select sum(cast(L_EXTENDEDPRICE * 3.21506374375027E33 as FLOAT8)) from lineitem where l_quantity
> 0
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tajo/blob/46c1cf56/tajo-core/src/test/resources/queries/TestSelectQuery/testSumIntOverflow.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestSelectQuery/testSumIntOverflow.sql b/tajo-core/src/test/resources/queries/TestSelectQuery/testSumIntOverflow.sql
new file mode 100644
index 0000000..96421eb
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestSelectQuery/testSumIntOverflow.sql
@@ -0,0 +1 @@
+select sum(cast(l_quantity * 25264513 as INT4)) from lineitem where l_quantity > 0
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tajo/blob/46c1cf56/tajo-core/src/test/resources/results/TestSelectQuery/testSumFloatOverflow.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestSelectQuery/testSumFloatOverflow.result
b/tajo-core/src/test/resources/results/TestSelectQuery/testSumFloatOverflow.result
new file mode 100644
index 0000000..13b9ef4
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestSelectQuery/testSumFloatOverflow.result
@@ -0,0 +1,3 @@
+?sum
+-------------------------------
+6.838452478692677E38
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tajo/blob/46c1cf56/tajo-core/src/test/resources/results/TestSelectQuery/testSumIntOverflow.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestSelectQuery/testSumIntOverflow.result
b/tajo-core/src/test/resources/results/TestSelectQuery/testSumIntOverflow.result
new file mode 100644
index 0000000..cf2e0a8
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestSelectQuery/testSumIntOverflow.result
@@ -0,0 +1,3 @@
+?sum
+-------------------------------
+4673934905
\ No newline at end of file
|