org.apache.spark.sql.types
Class Decimal

Object
  extended by org.apache.spark.sql.types.Decimal
All Implemented Interfaces:
java.io.Serializable, Comparable<Decimal>, scala.math.Ordered<Decimal>

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)

See Also:
Serialized Form

Constructor Summary
Decimal()
           
 
Method Summary
static Decimal apply(scala.math.BigDecimal value)
           
static Decimal apply(java.math.BigDecimal value)
           
static Decimal apply(scala.math.BigDecimal value, int precision, int scale)
           
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 apply(String value)
           
 boolean changePrecision(int precision, int scale)
          Update precision and scale while keeping our value the same, and return true if successful.
 Decimal clone()
           
 int compare(Decimal other)
           
 boolean equals(Object other)
           
 int hashCode()
           
 boolean isZero()
           
static int MAX_LONG_DIGITS()
          Maximum number of decimal digits a Long can represent
 int precision()
           
 Decimal remainder(Decimal that)
           
 int scale()
           
 Decimal set(scala.math.BigDecimal decimal)
          Set this Decimal to the given BigDecimal value, inheriting its precision and scale.
 Decimal set(scala.math.BigDecimal decimal, int precision, int scale)
          Set this Decimal to the given BigDecimal value, with a given precision and scale.
 Decimal set(Decimal decimal)
          Set this Decimal to the given Decimal value.
 Decimal set(int intVal)
          Set this Decimal to the given Int.
 Decimal set(long longVal)
          Set this Decimal to the given Long.
 Decimal set(long unscaled, int precision, int scale)
          Set this Decimal to the given unscaled Long, with a given precision and scale.
 Decimal 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 toBigDecimal()
           
 byte toByte()
           
 String toDebugString()
           
 double toDouble()
           
 float toFloat()
           
 int toInt()
           
 java.math.BigDecimal toJavaBigDecimal()
           
 long toLong()
           
 short toShort()
           
 String toString()
           
 long toUnscaledLong()
           
 
Methods inherited from class Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface scala.math.Ordered
$greater, $greater$eq, $less, $less$eq, compareTo
 

Constructor Detail

Decimal

public Decimal()
Method Detail

MAX_LONG_DIGITS

public static int MAX_LONG_DIGITS()
Maximum number of decimal digits a Long can represent


apply

public static Decimal apply(double value)

apply

public static Decimal apply(long value)

apply

public static Decimal apply(int value)

apply

public static Decimal apply(scala.math.BigDecimal value)

apply

public static Decimal apply(java.math.BigDecimal value)

apply

public static Decimal apply(scala.math.BigDecimal value,
                            int precision,
                            int scale)

apply

public static Decimal apply(long unscaled,
                            int precision,
                            int scale)

apply

public static Decimal apply(String value)

precision

public int precision()

scale

public int scale()

set

public Decimal set(long longVal)
Set this Decimal to the given Long. Will have precision 20 and scale 0.

Parameters:
longVal - (undocumented)
Returns:
(undocumented)

set

public Decimal set(int intVal)
Set this Decimal to the given Int. Will have precision 10 and scale 0.

Parameters:
intVal - (undocumented)
Returns:
(undocumented)

set

public Decimal set(long unscaled,
                   int precision,
                   int scale)
Set this Decimal to the given unscaled Long, with a given precision and scale.

Parameters:
unscaled - (undocumented)
precision - (undocumented)
scale - (undocumented)
Returns:
(undocumented)

setOrNull

public Decimal 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.

Parameters:
unscaled - (undocumented)
precision - (undocumented)
scale - (undocumented)
Returns:
(undocumented)

set

public Decimal set(scala.math.BigDecimal decimal,
                   int precision,
                   int scale)
Set this Decimal to the given BigDecimal value, with a given precision and scale.

Parameters:
decimal - (undocumented)
precision - (undocumented)
scale - (undocumented)
Returns:
(undocumented)

set

public Decimal set(scala.math.BigDecimal decimal)
Set this Decimal to the given BigDecimal value, inheriting its precision and scale.

Parameters:
decimal - (undocumented)
Returns:
(undocumented)

set

public Decimal set(Decimal decimal)
Set this Decimal to the given Decimal value.

Parameters:
decimal - (undocumented)
Returns:
(undocumented)

toBigDecimal

public scala.math.BigDecimal toBigDecimal()

toJavaBigDecimal

public java.math.BigDecimal toJavaBigDecimal()

toUnscaledLong

public long toUnscaledLong()

toString

public String toString()
Overrides:
toString in class Object

toDebugString

public String 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

public Decimal clone()
Overrides:
clone in class Object

compare

public int compare(Decimal other)
Specified by:
compare in interface scala.math.Ordered<Decimal>

equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

isZero

public boolean isZero()

remainder

public Decimal remainder(Decimal that)