Class DecimalUtil

java.lang.Object
io.substrait.util.DecimalUtil

public class DecimalUtil extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    encodeDecimalIntoBytes(BigDecimal decimal, int scale, int byteWidth)
    Given a big decimal and its scale, convert into a scaled big integer, and then convert the scaled big integer into little-endian twos-complement with byeWidth bytes.
    static BigDecimal
    getBigDecimalFromBytes(byte[] value, int scale, int byteWidth)
    Given an input of little-endian twos-complement with byeWidth bytes of a scaled big integer, convert it back to BigDecimal.

    Methods inherited from class java.lang.Object

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

    • DecimalUtil

      public DecimalUtil()
  • Method Details

    • getBigDecimalFromBytes

      public static BigDecimal getBigDecimalFromBytes(byte[] value, int scale, int byteWidth)
      Given an input of little-endian twos-complement with byeWidth bytes of a scaled big integer, convert it back to BigDecimal. This method is the opposite of encodeDecimalIntoBytes()
      Parameters:
      value -
      scale -
      byteWidth -
      Returns:
    • encodeDecimalIntoBytes

      public static byte[] encodeDecimalIntoBytes(BigDecimal decimal, int scale, int byteWidth)
      Given a big decimal and its scale, convert into a scaled big integer, and then convert the scaled big integer into little-endian twos-complement with byeWidth bytes.
      Parameters:
      decimal -
      scale -
      byteWidth -
      Returns: