Package org.apache.arrow.vector.util
Class DecimalUtility
- java.lang.Object
-
- org.apache.arrow.vector.util.DecimalUtility
-
public class DecimalUtility extends Object
Utility methods for configurable precision Decimal values (e.g.BigDecimal).
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancheckPrecisionAndScale(int decimalPrecision, int decimalScale, int vectorPrecision, int vectorScale)Check that the decimal scale equals the vectorScale and that the decimal precision is less than or equal to the vectorPrecision.static booleancheckPrecisionAndScale(BigDecimal value, int vectorPrecision, int vectorScale)Check that the BigDecimal scale equals the vectorScale and that the BigDecimal precision is less than or equal to the vectorPrecision.static booleancheckPrecisionAndScaleNoThrow(BigDecimal value, int vectorPrecision, int vectorScale)Check that the BigDecimal scale equals the vectorScale and that the BigDecimal precision is less than or equal to the vectorPrecision.static BigDecimalgetBigDecimalFromArrowBuf(ArrowBuf bytebuf, int index, int scale, int byteWidth)Read an ArrowType.Decimal at the given value index in the ArrowBuf and convert to a BigDecimal with the given scale.static BigDecimalgetBigDecimalFromByteBuffer(ByteBuffer bytebuf, int scale, int byteWidth)Read an ArrowType.Decimal from the ByteBuffer and convert to a BigDecimal with the given scale.static byte[]getByteArrayFromArrowBuf(ArrowBuf bytebuf, int index, int byteWidth)Read an ArrowType.Decimal from the ArrowBuf at the given value index and return it as a byte array.static voidwriteBigDecimalToArrowBuf(BigDecimal value, ArrowBuf bytebuf, int index, int byteWidth)Write the given BigDecimal to the ArrowBuf at the given value index.static voidwriteByteArrayToArrowBuf(byte[] bytes, ArrowBuf bytebuf, int index, int byteWidth)Write the given byte array to the ArrowBuf at the given value index.static voidwriteLongToArrowBuf(long value, ArrowBuf bytebuf, int index, int byteWidth)Write the given long to the ArrowBuf at the given value index.
-
-
-
Method Detail
-
getBigDecimalFromArrowBuf
public static BigDecimal getBigDecimalFromArrowBuf(ArrowBuf bytebuf, int index, int scale, int byteWidth)
Read an ArrowType.Decimal at the given value index in the ArrowBuf and convert to a BigDecimal with the given scale.
-
getBigDecimalFromByteBuffer
public static BigDecimal getBigDecimalFromByteBuffer(ByteBuffer bytebuf, int scale, int byteWidth)
Read an ArrowType.Decimal from the ByteBuffer and convert to a BigDecimal with the given scale.
-
getByteArrayFromArrowBuf
public static byte[] getByteArrayFromArrowBuf(ArrowBuf bytebuf, int index, int byteWidth)
Read an ArrowType.Decimal from the ArrowBuf at the given value index and return it as a byte array.
-
checkPrecisionAndScale
public static boolean checkPrecisionAndScale(BigDecimal value, int vectorPrecision, int vectorScale)
Check that the BigDecimal scale equals the vectorScale and that the BigDecimal precision is less than or equal to the vectorPrecision. If not, then an UnsupportedOperationException is thrown, otherwise returns true.
-
checkPrecisionAndScaleNoThrow
public static boolean checkPrecisionAndScaleNoThrow(BigDecimal value, int vectorPrecision, int vectorScale)
Check that the BigDecimal scale equals the vectorScale and that the BigDecimal precision is less than or equal to the vectorPrecision. Return true if so, otherwise return false.
-
checkPrecisionAndScale
public static boolean checkPrecisionAndScale(int decimalPrecision, int decimalScale, int vectorPrecision, int vectorScale)Check that the decimal scale equals the vectorScale and that the decimal precision is less than or equal to the vectorPrecision. If not, then an UnsupportedOperationException is thrown, otherwise returns true.
-
writeBigDecimalToArrowBuf
public static void writeBigDecimalToArrowBuf(BigDecimal value, ArrowBuf bytebuf, int index, int byteWidth)
Write the given BigDecimal to the ArrowBuf at the given value index. Will throw an UnsupportedOperationException if the decimal size is greater than the Decimal vector byte width.
-
writeLongToArrowBuf
public static void writeLongToArrowBuf(long value, ArrowBuf bytebuf, int index, int byteWidth)Write the given long to the ArrowBuf at the given value index. This routine extends the original sign bit to a new upper area in 128-bit or 256-bit.
-
writeByteArrayToArrowBuf
public static void writeByteArrayToArrowBuf(byte[] bytes, ArrowBuf bytebuf, int index, int byteWidth)Write the given byte array to the ArrowBuf at the given value index. Will throw an UnsupportedOperationException if the decimal size is greater than the Decimal vector byte width.
-
-