Package org.apache.spark.sql.types
Class Decimal
Object
org.apache.spark.sql.types.Decimal
- All Implemented Interfaces:
Serializable
,Comparable<Decimal>
,scala.math.Ordered<Decimal>
,scala.Serializable
public final class Decimal
extends Object
implements scala.math.Ordered<Decimal>, scala.Serializable
A mutable implementation of BigDecimal that can hold a Long if values are small enough.
The semantics of the fields are as follows: - _precision and _scale represent the SQL precision and scale we are looking for - If decimalVal is set, it represents the whole decimal value - Otherwise, the decimal value is longVal / (10 ** _scale)
Note, for values between -1.0 and 1.0, precision digits are only counted after dot.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
AIntegral
evidence parameter for Decimals.static interface
Common methods for Decimal evidence parametersstatic class
AFractional
evidence parameter for Decimals. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabs()
static Decimal
apply
(double value) static Decimal
apply
(int value) static Decimal
apply
(long value) static Decimal
apply
(long unscaled, int precision, int scale) static Decimal
static Decimal
apply
(BigDecimal value) static Decimal
apply
(BigDecimal value, int precision, int scale) static Decimal
apply
(BigInteger value) static Decimal
apply
(scala.math.BigDecimal value) static Decimal
apply
(scala.math.BigDecimal value, int precision, int scale) static Decimal
apply
(scala.math.BigInt value) ceil()
boolean
changePrecision
(int precision, int scale) Update precision and scale while keeping our value the same, and return true if successful.clone()
int
static Decimal
createUnsafe
(long unscaled, int precision, int scale) Creates a decimal from unscaled, precision and scale without checking the bounds.boolean
floor()
static Decimal
fromDecimal
(Object value) static Decimal
fromString
(org.apache.spark.unsafe.types.UTF8String str) static Decimal
fromStringANSI
(org.apache.spark.unsafe.types.UTF8String str, DecimalType to, org.apache.spark.sql.catalyst.trees.SQLQueryContext context) int
hashCode()
boolean
isZero()
static int
Maximum number of decimal digits an Int can representstatic int
Maximum number of decimal digits a Long can representstatic int
maxPrecisionForBytes
(int numBytes) static int[]
static long[]
POW_10()
int
static scala.Enumeration.Value
static scala.Enumeration.Value
static scala.Enumeration.Value
static scala.Enumeration.Value
int
scale()
set
(int intVal) Set this Decimal to the given Int.set
(long longVal) Set this Decimal to the given Long.set
(long unscaled, int precision, int scale) Set this Decimal to the given unscaled Long, with a given precision and scale.set
(BigInteger bigintval) If the value is not in the range of long, convert it to BigDecimal and the precision and scale are based on the converted value.Set this Decimal to the given Decimal value.set
(scala.math.BigDecimal decimal) Set this Decimal to the given BigDecimal value, inheriting its precision and scale.set
(scala.math.BigDecimal decimal, int precision, int scale) Set this Decimal to the given BigDecimal value, with a given precision and scale.setOrNull
(long unscaled, int precision, int scale) Set this Decimal to the given unscaled Long, with a given precision and scale, and return it, or return null if it cannot be set due to overflow.scala.math.BigDecimal
byte
toByte()
double
toDouble()
float
toFloat()
int
toInt()
long
toLong()
scala.math.BigInt
short
toShort()
toString()
long
Methods inherited from interface scala.math.Ordered
$greater, $greater$eq, $less, $less$eq, compareTo
-
Constructor Details
-
Decimal
public Decimal()
-
-
Method Details
-
ROUND_HALF_UP
public static scala.Enumeration.Value ROUND_HALF_UP() -
ROUND_HALF_EVEN
public static scala.Enumeration.Value ROUND_HALF_EVEN() -
ROUND_CEILING
public static scala.Enumeration.Value ROUND_CEILING() -
ROUND_FLOOR
public static scala.Enumeration.Value ROUND_FLOOR() -
MAX_INT_DIGITS
public static int MAX_INT_DIGITS()Maximum number of decimal digits an Int can represent -
MAX_LONG_DIGITS
public static int MAX_LONG_DIGITS()Maximum number of decimal digits a Long can represent -
POW_10
public static long[] POW_10() -
apply
-
apply
-
apply
-
apply
-
apply
-
apply
-
apply
-
apply
-
apply
-
apply
-
apply
-
fromDecimal
-
fromString
-
fromStringANSI
public static Decimal fromStringANSI(org.apache.spark.unsafe.types.UTF8String str, DecimalType to, org.apache.spark.sql.catalyst.trees.SQLQueryContext context) -
createUnsafe
Creates a decimal from unscaled, precision and scale without checking the bounds.- Parameters:
unscaled
- (undocumented)precision
- (undocumented)scale
- (undocumented)- Returns:
- (undocumented)
-
maxPrecisionForBytes
public static int maxPrecisionForBytes(int numBytes) -
minBytesForPrecision
public static int[] minBytesForPrecision() -
precision
public int precision() -
scale
public int scale() -
set
Set this Decimal to the given Long. Will have precision 20 and scale 0.- Parameters:
longVal
- (undocumented)- Returns:
- (undocumented)
-
set
Set this Decimal to the given Int. Will have precision 10 and scale 0.- Parameters:
intVal
- (undocumented)- Returns:
- (undocumented)
-
set
Set this Decimal to the given unscaled Long, with a given precision and scale.- Parameters:
unscaled
- (undocumented)precision
- (undocumented)scale
- (undocumented)- Returns:
- (undocumented)
-
setOrNull
Set this Decimal to the given unscaled Long, with a given precision and scale, and return it, or return null if it cannot be set due to overflow.- Parameters:
unscaled
- (undocumented)precision
- (undocumented)scale
- (undocumented)- Returns:
- (undocumented)
-
set
Set this Decimal to the given BigDecimal value, with a given precision and scale.- Parameters:
decimal
- (undocumented)precision
- (undocumented)scale
- (undocumented)- Returns:
- (undocumented)
-
set
Set this Decimal to the given BigDecimal value, inheriting its precision and scale.- Parameters:
decimal
- (undocumented)- Returns:
- (undocumented)
-
set
If the value is not in the range of long, convert it to BigDecimal and the precision and scale are based on the converted value.This code avoids BigDecimal object allocation as possible to improve runtime efficiency
- Parameters:
bigintval
- (undocumented)- Returns:
- (undocumented)
-
set
Set this Decimal to the given Decimal value.- Parameters:
decimal
- (undocumented)- Returns:
- (undocumented)
-
toBigDecimal
public scala.math.BigDecimal toBigDecimal() -
toJavaBigDecimal
-
toScalaBigInt
public scala.math.BigInt toScalaBigInt() -
toJavaBigInteger
-
toUnscaledLong
public long toUnscaledLong() -
toString
-
toPlainString
-
toDebugString
-
toDouble
public double toDouble() -
toFloat
public float toFloat() -
toLong
public long toLong() -
toInt
public int toInt() -
toShort
public short toShort() -
toByte
public byte toByte() -
changePrecision
public boolean changePrecision(int precision, int scale) Update precision and scale while keeping our value the same, and return true if successful.- Parameters:
precision
- (undocumented)scale
- (undocumented)- Returns:
- true if successful, false if overflow would occur
-
clone
-
compare
- Specified by:
compare
in interfacescala.math.Ordered<Decimal>
-
equals
-
hashCode
public int hashCode() -
isZero
public boolean isZero() -
quot
-
remainder
-
abs
-
floor
-
ceil
-