DRILL-1016: Propagate negative sign while casting from decimal18 to 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/da618239 Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/da618239 Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/da618239 Branch: refs/heads/master Commit: da618239d7f1347706e0e183ed0547e6e257762f Parents: 43bb57e Author: Mehant Baid <[email protected]> Authored: Wed Jun 18 22:16:36 2014 -0700 Committer: Jacques Nadeau <[email protected]> Committed: Fri Jun 20 10:56:15 2014 -0700 ---------------------------------------------------------------------- .../codegen/templates/Decimal/CastSrcDecimalSimple.java | 3 ++- .../org/apache/drill/jdbc/test/TestFunctionsQuery.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/da618239/exec/java-exec/src/main/codegen/templates/Decimal/CastSrcDecimalSimple.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastSrcDecimalSimple.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastSrcDecimalSimple.java index 7ef806f..aac45e0 100644 --- a/exec/java-exec/src/main/codegen/templates/Decimal/CastSrcDecimalSimple.java +++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastSrcDecimalSimple.java @@ -169,7 +169,6 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ out.buffer = buffer; out.start = 0; - out.setSign((in.value < 0)); /* Since we will be dividing the decimal value with base 1 billion * we don't want negative results if the decimal is negative. @@ -213,6 +212,8 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc{ if (in.scale != out.scale) { org.apache.drill.common.util.DecimalUtility.roundDecimal(out.buffer, out.start, out.nDecimalDigits, out.scale, in.scale); } + // Set the sign + out.setSign((in.value < 0)); } } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/da618239/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 39919a5..64bdf6d 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 @@ -559,4 +559,15 @@ public class TestFunctionsQuery { .sql(query) .returns("col1=2003-07-09; col2=2003-07-09; col3=2003-07-09"); } + + @Test + public void testDecimal18Decimal38Comparison() throws Exception { + String query = "select cast('999999999.999999999' as decimal(18, 9)) = cast('999999999.999999999' as decimal(38, 18)) as CMP " + + "from cp.`employee.json` where employee_id = 1"; + + JdbcAssert.withNoDefaultSchema() + .sql(query) + .returns( + "CMP=true\n"); + } }
