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).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final byte[]
     
    static final byte[]
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    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.
    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.
    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.
    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 void
    writeBigDecimalToArrowBuf(BigDecimal value, ArrowBuf bytebuf, int index, int byteWidth)
    Write the given BigDecimal to the ArrowBuf at the given value index.
    static void
    writeByteArrayToArrowBuf(byte[] bytes, ArrowBuf bytebuf, int index, int byteWidth)
    Write the given byte array to the ArrowBuf at the given value index.
    static void
    writeLongToArrowBuf(long value, ArrowBuf bytebuf, int index, int byteWidth)
    Write the given long to the ArrowBuf at the given value index.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • zeroes

      public static final byte[] zeroes
    • minus_one

      public static final byte[] minus_one
  • Method Details

    • 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.