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 int
compareTo(DecimalData that)
DecimalData
copy()
Returns a copy of thisDecimalData
object.boolean
equals(Object o)
static DecimalData
fromBigDecimal(BigDecimal bd, int precision, int scale)
Creates an instance ofDecimalData
from aBigDecimal
and the given precision and scale.static DecimalData
fromUnscaledBytes(byte[] unscaledBytes, int precision, int scale)
Creates an instance ofDecimalData
from an unscaled byte array value and the given precision and scale.static DecimalData
fromUnscaledLong(long unscaledLong, int precision, int scale)
Creates an instance ofDecimalData
from an unscaled long value and the given precision and scale.int
hashCode()
boolean
isCompact()
Returns whether the decimal value is small enough to be stored in a long.static boolean
isCompact(int precision)
Returns whether the decimal value is small enough to be stored in a long.int
precision()
Returns the precision of thisDecimalData
.int
scale()
Returns the scale of thisDecimalData
.BigDecimal
toBigDecimal()
Converts thisDecimalData
into an instance ofBigDecimal
.String
toString()
byte[]
toUnscaledBytes()
Returns a byte array describing the unscaled value of thisDecimalData
.long
toUnscaledLong()
Returns a long describing the unscaled value of thisDecimalData
.static DecimalData
zero(int precision, int scale)
Creates an instance ofDecimalData
for 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 thisDecimalData
into an instance ofBigDecimal
.
-
toUnscaledLong
public long toUnscaledLong()
Returns a long describing the unscaled value of thisDecimalData
.- Throws:
ArithmeticException
- if thisDecimalData
does 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 thisDecimalData
object.
-
compareTo
public int compareTo(@Nonnull DecimalData that)
- Specified by:
compareTo
in interfaceComparable<DecimalData>
-
fromBigDecimal
@Nullable public static DecimalData fromBigDecimal(BigDecimal bd, int precision, int scale)
Creates an instance ofDecimalData
from aBigDecimal
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 ofDecimalData
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 ofDecimalData
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 ofDecimalData
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.
-
-