DRILL-770: Fix decimal math functions with constants
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/62c0b1ba Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/62c0b1ba Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/62c0b1ba Branch: refs/heads/master Commit: 62c0b1ba384fd2b3c7a9af12ed75341a4294f331 Parents: 5a78ff8 Author: Mehant Baid <[email protected]> Authored: Sun May 18 18:31:57 2014 -0700 Committer: Mehant Baid <[email protected]> Committed: Mon May 19 10:43:26 2014 -0700 ---------------------------------------------------------------------- .../codegen/templates/Decimal/DecimalFunctions.java | 2 ++ .../apache/drill/exec/resolver/TypeCastRules.java | 6 ------ .../apache/drill/jdbc/test/TestFunctionsQuery.java | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62c0b1ba/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java index 8f14e83..cff122e 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/DecimalFunctions.java @@ -237,8 +237,10 @@ import org.apache.drill.exec.expr.annotations.Workspace; if (left.scale < right.scale) { left.value = (${javaType}) (left.value * Math.pow(10, (right.scale - left.scale))); + left.scale = right.scale; } else if (right.scale < left.scale) { right.value = (${javaType}) (right.value * Math.pow(10, (left.scale - right.scale))); + right.scale = left.scale; } </#macro> http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62c0b1ba/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java index 515843d..2f6bf38 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java @@ -420,12 +420,6 @@ public class TypeCastRules { rule.add(MinorType.UINT2); rule.add(MinorType.UINT4); rule.add(MinorType.UINT8); - rule.add(MinorType.DECIMAL9); - rule.add(MinorType.DECIMAL18); - rule.add(MinorType.DECIMAL28SPARSE); - rule.add(MinorType.DECIMAL28DENSE); - rule.add(MinorType.DECIMAL38SPARSE); - rule.add(MinorType.DECIMAL38DENSE); rule.add(MinorType.DATE); rule.add(MinorType.TIME); rule.add(MinorType.TIMESTAMPTZ); http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/62c0b1ba/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 05884e5..66ae477 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 @@ -452,4 +452,19 @@ public class TestFunctionsQuery { "CNT=1.000\n" + "CNT=3.000\n"); } + + @Test + public void testDecimalAddIntConstant() throws Exception { + String query = "select 1 + cast(employee_id as decimal(9, 3)) as DEC_9 , 1 + cast(employee_id as decimal(38, 5)) as DEC_38 " + + "from cp.`employee.json` where employee_id <= 2"; + + JdbcAssert.withNoDefaultSchema() + .sql(query) + .returns( + "DEC_9=2.000; " + + "DEC_38=2.00000\n" + + "DEC_9=3.000; " + + "DEC_38=3.00000\n"); + } + }
