You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicstaticBigDecimalbinaryToDecimal(Binaryvalue, intprecision, intscale) {
/* * Precision <= 18 checks for the max number of digits for an unscaled long, * else treat with big integer conversion */if (precision <= 18) {
ByteBufferbuffer = value.toByteBuffer();
byte[] bytes = buffer.array();
intstart = buffer.arrayOffset() + buffer.position();
intend = buffer.arrayOffset() + buffer.limit();
longunscaled = 0L;
inti = start;
while (i < end) {
unscaled = (unscaled << 8 | bytes[i] & 0xff);
i++;
}
intbits = 8 * (end - start);
longunscaledNew = (unscaled << (64 - bits)) >> (64 - bits);
if (unscaledNew <= -pow(10, 18) || unscaledNew >= pow(10, 18)) {
returnnewBigDecimal(unscaledNew);
} else {
returnBigDecimal.valueOf(unscaledNew / pow(10, scale));
}
} else {
returnnewBigDecimal(newBigInteger(value.getBytes()), scale);
}
}
If precision is less than 18, the condition unscaledNew <= -pow(10, 18) || unscaledNew >= pow(10, 18) can not be true, so we can remove the judgment logic here. Additionally, using BigDecimal.valueOf(unscaledNew, scale) is preferable over using BigDecimal.valueOf(unscaledNew / pow(10, scale)), as it does not convert the unscaled value to double.
Component(s)
No response
The text was updated successfully, but these errors were encountered:
Describe the enhancement requested
https://github.com/apache/parquet-java/blob/master/parquet-pig/src/main/java/org/apache/parquet/pig/convert/DecimalUtils.java
If precision is less than 18, the condition
unscaledNew <= -pow(10, 18) || unscaledNew >= pow(10, 18)
can not be true, so we can remove the judgment logic here. Additionally, usingBigDecimal.valueOf(unscaledNew, scale)
is preferable over usingBigDecimal.valueOf(unscaledNew / pow(10, scale))
, as it does not convert the unscaled value to double.Component(s)
No response
The text was updated successfully, but these errors were encountered: