Class DecimalData

java.lang.Object
org.apache.flink.table.data.DecimalData
All Implemented Interfaces:
Comparable<DecimalData>

@PublicEvolving public final class DecimalData extends Object implements Comparable<DecimalData>
An internal data structure representing data of DecimalType.

This data structure is immutable and might store decimal values in a compact representation (as a long value) if values are small enough.

  • Method Details

    • precision

      public int precision()
      Returns the precision of this DecimalData.

      The precision is the number of digits in the unscaled value.

    • scale

      public int scale()
      Returns the scale of this DecimalData.
    • toBigDecimal

      public BigDecimal toBigDecimal()
      Converts this DecimalData into an instance of BigDecimal.
    • toUnscaledLong

      public long toUnscaledLong()
      Returns a long describing the unscaled value of this DecimalData.
      Throws:
      ArithmeticException - if this DecimalData does not exactly fit in a long.
    • toUnscaledBytes

      public byte[] toUnscaledBytes()
      Returns a byte array describing the unscaled value of this DecimalData.
      Returns:
      the unscaled byte array of this DecimalData.
    • isCompact

      public boolean isCompact()
      Returns whether the decimal value is small enough to be stored in a long.
    • copy

      public DecimalData copy()
      Returns a copy of this DecimalData object.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(@Nonnull DecimalData that)
      Specified by:
      compareTo in interface Comparable<DecimalData>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • fromBigDecimal

      @Nullable public static DecimalData fromBigDecimal(BigDecimal bd, int precision, int scale)
      Creates an instance of DecimalData from a BigDecimal and the given precision and scale.

      The returned decimal value may be rounded to have the desired scale. The precision will be checked. If the precision overflows, null will be returned.

    • fromUnscaledLong

      public static DecimalData fromUnscaledLong(long unscaledLong, int precision, int scale)
      Creates an instance of DecimalData from an unscaled long value and the given precision and scale.
    • fromUnscaledBytes

      public static DecimalData fromUnscaledBytes(byte[] unscaledBytes, int precision, int scale)
      Creates an instance of DecimalData from an unscaled byte array value and the given precision and scale.
    • zero

      @Nullable public static DecimalData zero(int precision, int scale)
      Creates an instance of DecimalData for a zero value with the given precision and scale.

      The precision will be checked. If the precision overflows, null will be returned.

    • isCompact

      public static boolean isCompact(int precision)
      Returns whether the decimal value is small enough to be stored in a long.