From 0265db5d5e954991bd51fb02131eabcc185a0185 Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Thu, 18 Jul 2024 11:48:33 -0700 Subject: [PATCH] chore: Skip creation of BigDecimal during getDecimal call --- .../org/apache/comet/vector/CometVector.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/org/apache/comet/vector/CometVector.java b/common/src/main/java/org/apache/comet/vector/CometVector.java index 27f40bace9..6aae0383a9 100644 --- a/common/src/main/java/org/apache/comet/vector/CometVector.java +++ b/common/src/main/java/org/apache/comet/vector/CometVector.java @@ -79,14 +79,23 @@ public Decimal getDecimal(int i, int precision, int scale) { } else { byte[] bytes = getBinaryDecimal(i); BigInteger bigInteger = new BigInteger(bytes); - BigDecimal javaDecimal = new BigDecimal(bigInteger, scale); try { - return Decimal.apply(javaDecimal, precision, scale); + Decimal d = Decimal.apply(bigInteger); + boolean success = d.changePrecision(precision, scale); + if (!success) { + throw new ArithmeticException( + "Overflowing when convert " + + bigInteger + + " to decimal with precision: " + + precision + + " and scale: " + + scale); + } + return d; } catch (ArithmeticException e) { throw new ArithmeticException( "Cannot convert " - + javaDecimal - + " (bytes: " + + "(bytes: " + bytes + ", integer: " + bigInteger