diff options
author | Mehant Baid <mehantr@gmail.com> | 2014-07-02 02:29:54 -0700 |
---|---|---|
committer | Jacques Nadeau <jacques@apache.org> | 2014-07-03 08:59:48 -0700 |
commit | 22709c2185778a61b10ab96fe8b04b170dc25c68 (patch) | |
tree | fcfef209f1c027c282d59c7ad77bb15be95979eb /common | |
parent | de8f3592ee716351b1694f48b797c89e2837caa7 (diff) |
DRILL-1085: Round up while casting to int/bigint from float/double/decimal
Diffstat (limited to 'common')
-rw-r--r-- | common/src/main/java/org/apache/drill/common/util/DecimalUtility.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/common/src/main/java/org/apache/drill/common/util/DecimalUtility.java b/common/src/main/java/org/apache/drill/common/util/DecimalUtility.java index 0ac870a1a..4f9f09601 100644 --- a/common/src/main/java/org/apache/drill/common/util/DecimalUtility.java +++ b/common/src/main/java/org/apache/drill/common/util/DecimalUtility.java @@ -684,5 +684,30 @@ public class DecimalUtility { public static int getPrecisionRange(int precision) { return getMaxPrecision(getDecimalDataType(precision)); } + + public static int getFirstFractionalDigit(int decimal, int scale) { + if (scale == 0) { + return 0; + } + int temp = (int) adjustScaleDivide(decimal, scale - 1); + return Math.abs(temp % 10); + } + + public static int getFirstFractionalDigit(long decimal, int scale) { + if (scale == 0) { + return 0; + } + long temp = adjustScaleDivide(decimal, scale - 1); + return (int) (Math.abs(temp % 10)); + } + + public static int getFirstFractionalDigit(ByteBuf data, int scale, int start, int nDecimalDigits) { + if (scale == 0) { + return 0; + } + + int index = nDecimalDigits - roundUp(scale); + return (int) (adjustScaleDivide(data.getInt(start + (index * integerSize)), MAX_DIGITS - 1)); + } } |