Package org.apache.flink.table.data
Class DecimalData
java.lang.Object
org.apache.flink.table.data.DecimalData
- All Implemented Interfaces:
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 Summary
Modifier and TypeMethodDescriptionintcompareTo(DecimalData that) copy()Returns a copy of thisDecimalDataobject.booleanstatic DecimalDatafromBigDecimal(BigDecimal bd, int precision, int scale) Creates an instance ofDecimalDatafrom aBigDecimaland the given precision and scale.static DecimalDatafromUnscaledBytes(byte[] unscaledBytes, int precision, int scale) Creates an instance ofDecimalDatafrom an unscaled byte array value and the given precision and scale.static DecimalDatafromUnscaledLong(long unscaledLong, int precision, int scale) Creates an instance ofDecimalDatafrom an unscaled long value and the given precision and scale.inthashCode()booleanReturns whether the decimal value is small enough to be stored in a long.static booleanisCompact(int precision) Returns whether the decimal value is small enough to be stored in a long.intReturns the precision of thisDecimalData.intscale()Returns the scale of thisDecimalData.Converts thisDecimalDatainto an instance ofBigDecimal.toString()byte[]Returns a byte array describing the unscaled value of thisDecimalData.longReturns a long describing the unscaled value of thisDecimalData.static DecimalDatazero(int precision, int scale) Creates an instance ofDecimalDatafor a zero value with the given precision and scale.
-
Method Details
-
precision
public int precision()Returns the precision of thisDecimalData.The precision is the number of digits in the unscaled value.
-
scale
public int scale()Returns the scale of thisDecimalData. -
toBigDecimal
Converts thisDecimalDatainto an instance ofBigDecimal. -
toUnscaledLong
public long toUnscaledLong()Returns a long describing the unscaled value of thisDecimalData.- Throws:
ArithmeticException- if thisDecimalDatadoes not exactly fit in a long.
-
toUnscaledBytes
public byte[] toUnscaledBytes()Returns a byte array describing the unscaled value of thisDecimalData.- 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
Returns a copy of thisDecimalDataobject. -
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<DecimalData>
-
equals
-
toString
-
fromBigDecimal
Creates an instance ofDecimalDatafrom aBigDecimaland 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
Creates an instance ofDecimalDatafrom an unscaled long value and the given precision and scale. -
fromUnscaledBytes
Creates an instance ofDecimalDatafrom an unscaled byte array value and the given precision and scale. -
zero
Creates an instance ofDecimalDatafor 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.
-