Repository: incubator-drill Updated Branches: refs/heads/master 63b034676 -> e7a486d78
DRILL-607, DRILL-593: Fix casting from Int, BigInt to Decimal28, Decimal38 Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/2631bbce Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/2631bbce Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/2631bbce Branch: refs/heads/master Commit: 2631bbce6dcb1e5120462e3496ee9c4ae4caa71e Parents: 63b0346 Author: mehant <[email protected]> Authored: Wed May 7 01:45:04 2014 -0700 Committer: Aditya Kishore <[email protected]> Committed: Mon May 12 21:33:14 2014 -0700 ---------------------------------------------------------------------- .../codegen/templates/Decimal/CastIntDecimal.java | 11 ++--------- .../apache/drill/jdbc/test/TestFunctionsQuery.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2631bbce/exec/java-exec/src/main/codegen/templates/Decimal/CastIntDecimal.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastIntDecimal.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastIntDecimal.java index 1efe21f..525566a 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/CastIntDecimal.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastIntDecimal.java @@ -59,7 +59,6 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { } public void eval() { - out.scale = (int) scale.value; out.precision = (int) precision.value; @@ -81,20 +80,14 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc { // check if input is a negative number and store the sign if (in.value < 0) { out.sign = true; - /* we are going to split the input into base 1 billion numbers - * by dividing, if we leave the input to be negative all the splits - * will be negative. We store the sign in the output at the end in the - * most significant bit - */ - in.value = in.value * -1; } // Figure out how many array positions to be left for the scale part int scaleSize = org.apache.drill.common.util.DecimalUtility.roundUp((int) scale.value); int integerIndex = (${type.arraySize} - scaleSize - 1); - while (in.value > 0 && integerIndex >= 0) { - out.setInteger(integerIndex, (int) (in.value % org.apache.drill.common.util.DecimalUtility.DIGITS_BASE)); + while (in.value != 0 && integerIndex >= 0) { + out.setInteger(integerIndex--, (int) Math.abs((in.value % org.apache.drill.common.util.DecimalUtility.DIGITS_BASE))); in.value = in.value / org.apache.drill.common.util.DecimalUtility.DIGITS_BASE; } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2631bbce/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java index 1c78b5f..79f29c8 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestFunctionsQuery.java @@ -17,6 +17,7 @@ */ package org.apache.drill.jdbc.test; +import java.lang.Exception; import java.nio.file.Paths; import java.sql.Connection; import java.sql.DriverManager; @@ -416,4 +417,17 @@ public class TestFunctionsQuery { ); } + @Test + public void testIntMinToDecimal() throws Exception { + String query = "select cast((employee_id - employee_id + -2147483648) as decimal(28, 2)) as DEC_28," + + "cast((employee_id - employee_id + -2147483648) as decimal(18, 2)) as DEC_18 from " + + "cp.`employee.json` limit 1"; + + JdbcAssert.withNoDefaultSchema() + .sql(query) + .returns( + "DEC_28=-2147483648.00; " + + "DEC_18=-2147483648.00\n" + ); + } }
