aboutsummaryrefslogtreecommitdiff
path: root/exec/java-exec/src/main
diff options
context:
space:
mode:
authorMehant Baid <mehantr@gmail.com>2014-07-31 18:22:34 -0700
committerJacques Nadeau <jacques@apache.org>2014-08-06 16:44:21 -0700
commitabaf5c494eb97643385f93496eac4d18cf285ec6 (patch)
treecb422c1244e0dd6999f2c8de3b781ad1449a2fc8 /exec/java-exec/src/main
parent66c055ee5ed2d000b7bd6997875cad18616bccb6 (diff)
DRILL-1246: Fix rounding when scale is zero while casting from varchar ->decimal28/decimal38
Diffstat (limited to 'exec/java-exec/src/main')
-rw-r--r--exec/java-exec/src/main/codegen/templates/Decimal/CastVarCharDecimal.java12
1 files changed, 7 insertions, 5 deletions
diff --git a/exec/java-exec/src/main/codegen/templates/Decimal/CastVarCharDecimal.java b/exec/java-exec/src/main/codegen/templates/Decimal/CastVarCharDecimal.java
index 8a50bb65e..54232eafe 100644
--- a/exec/java-exec/src/main/codegen/templates/Decimal/CastVarCharDecimal.java
+++ b/exec/java-exec/src/main/codegen/templates/Decimal/CastVarCharDecimal.java
@@ -162,7 +162,7 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc {
}
}
-<#elseif type.major == "VarCharDecimalComplex"> <#-- Cast function template for conversion from VarChar to Decimal9, Decimal18 -->
+<#elseif type.major == "VarCharDecimalComplex"> <#-- Cast function template for conversion from VarChar to Decimal28, Decimal38 -->
<@pp.changeOutputFile name="/org/apache/drill/exec/expr/fn/impl/gcast/Cast${type.from}${type.to}.java" />
<#include "/@includes/license.ftl" />
@@ -329,10 +329,10 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc {
}
// Traverse and extract the fractional part
- decimalBufferIndex = ${type.arraySize} - scaleRoundedUp;
+ decimalBufferIndex = (scaleRoundedUp > 0) ? (${type.arraySize} - scaleRoundedUp) : (${type.arraySize} - 1);
ndigits = 0;
- if (scaleIndex != -1 && out.scale > 0) {
+ if (scaleIndex != -1) {
while (scaleIndex < scaleEndIndex) {
// check if we have scanned MAX_DIGITS and we need to move to the next index
@@ -378,8 +378,10 @@ public class Cast${type.from}${type.to} implements DrillSimpleFunc {
}
}
// Pad zeroes in the fractional part so that number of digits = MAX_DIGITS
- int padding = (int) org.apache.drill.common.util.DecimalUtility.getPowerOfTen((int) (org.apache.drill.common.util.DecimalUtility.MAX_DIGITS - ndigits));
- out.setInteger(decimalBufferIndex, out.getInteger(decimalBufferIndex) * padding);
+ if (out.scale > 0) {
+ int padding = (int) org.apache.drill.common.util.DecimalUtility.getPowerOfTen((int) (org.apache.drill.common.util.DecimalUtility.MAX_DIGITS - ndigits));
+ out.setInteger(decimalBufferIndex, out.getInteger(decimalBufferIndex) * padding);
+ }
int carry = 0;
do {