Package org.apache.flink.table.data
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 ofDecimalType.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(DecimalData that)DecimalDatacopy()Returns a copy of thisDecimalDataobject.booleanequals(Object o)static 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()booleanisCompact()Returns 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.intprecision()Returns the precision of thisDecimalData.intscale()Returns the scale of thisDecimalData.BigDecimaltoBigDecimal()Converts thisDecimalDatainto an instance ofBigDecimal.StringtoString()byte[]toUnscaledBytes()Returns a byte array describing the unscaled value of thisDecimalData.longtoUnscaledLong()Returns 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 Detail
-
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
public BigDecimal 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
public DecimalData copy()
Returns a copy of thisDecimalDataobject.
-
compareTo
public int compareTo(@Nonnull DecimalData that)- Specified by:
compareToin interfaceComparable<DecimalData>
-
fromBigDecimal
@Nullable public static DecimalData fromBigDecimal(BigDecimal bd, int precision, int scale)
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
public static DecimalData fromUnscaledLong(long unscaledLong, int precision, int scale)
Creates an instance ofDecimalDatafrom an unscaled long value and the given precision and scale.
-
fromUnscaledBytes
public static DecimalData fromUnscaledBytes(byte[] unscaledBytes, int precision, int scale)
Creates an instance ofDecimalDatafrom an unscaled byte array value and the given precision and scale.
-
zero
@Nullable public static DecimalData zero(int precision, int scale)
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.
-
-