Package io.substrait.util
Class DecimalUtil
java.lang.Object
io.substrait.util.DecimalUtil
A set of utility methods to deal with convertion of decimal values. Part of code is adopted from
Apache Arrow /java/vector/src/main/java/org/apache/arrow/vector/util/DecimalUtility.java
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]encodeDecimalIntoBytes(BigDecimal decimal, int scale, int byteWidth) Encodes aBigDecimalinto a scaled big integer and serializes it as little-endian two's-complement bytes of fixedbyteWidth.static BigDecimalgetBigDecimalFromBytes(byte[] value, int scale, int byteWidth) Converts a little-endian two's-complement byte array of a scaled big integer into aBigDecimal.
-
Constructor Details
-
DecimalUtil
public DecimalUtil()
-
-
Method Details
-
getBigDecimalFromBytes
Converts a little-endian two's-complement byte array of a scaled big integer into aBigDecimal. Opposite ofencodeDecimalIntoBytes(BigDecimal, int, int).- Parameters:
value- the little-endian two's-complement bytesscale- the decimal scale to applybyteWidth- the number of bytes used for the integer representation- Returns:
- the reconstructed
BigDecimal
-
encodeDecimalIntoBytes
Encodes aBigDecimalinto a scaled big integer and serializes it as little-endian two's-complement bytes of fixedbyteWidth.- Parameters:
decimal- the decimal value to encodescale- the scale used to produce the scaled integerbyteWidth- the target width in bytes for the output- Returns:
- the encoded little-endian two's-complement byte array
- Throws:
UnsupportedOperationException- if the encoded integer exceedsbyteWidth
-