public class DecimalUtility extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DIGITS_BASE |
static int |
INTEGER_SIZE |
static int |
MAX_DIGITS |
static int |
MAX_DIGITS_BIGINT |
static int |
MAX_DIGITS_INT |
Constructor and Description |
---|
DecimalUtility() |
Modifier and Type | Method and Description |
---|---|
static void |
checkValueOverflow(BigDecimal value,
int desiredPrecision,
int desiredScale)
Checks that the specified value may be fit into the value with specified
desiredPrecision precision and desiredScale scale. |
static int |
compareVarLenBytes(DrillBuf left,
int leftStart,
int leftEnd,
int leftScale,
byte[] right,
int rightScale,
boolean absCompare)
Compares two VarDecimal values, still stored in Drill buffer and byte array
|
static int |
compareVarLenBytes(DrillBuf left,
int leftStart,
int leftEnd,
int leftScale,
DrillBuf right,
int rightStart,
int rightEnd,
int rightScale,
boolean absCompare)
Compares two VarDecimal values, still stored in their respective Drill buffers
|
static BigDecimal |
getBigDecimalFromDense(DrillBuf data,
int startIndex,
int nDecimalDigits,
int scale,
int maxPrecision,
int width)
Returns a BigDecimal object from the dense decimal representation.
|
static BigDecimal |
getBigDecimalFromDrillBuf(io.netty.buffer.ByteBuf data,
int startIndex,
int nDecimalDigits,
int scale,
boolean truncateScale)
Create a BigDecimal object using the data in the DrillBuf.
|
static BigDecimal |
getBigDecimalFromDrillBuf(DrillBuf bytebuf,
int start,
int length,
int scale)
Create a BigDecimal object using the data in the DrillBuf.
|
static BigDecimal |
getBigDecimalFromPrimitiveTypes(int input,
int scale)
Returns
BigDecimal value created from specified integer value with specified scale. |
static BigDecimal |
getBigDecimalFromPrimitiveTypes(long input,
int scale)
Returns
BigDecimal value created from specified long value with specified scale. |
static BigDecimal |
getBigDecimalFromSparse(DrillBuf data,
int startIndex,
int nDecimalDigits,
int scale)
Create a BigDecimal object using the data in the DrillBuf.
|
static long |
getDecimal18FromBigDecimal(BigDecimal input,
int scale)
Returns unsigned long value taken from specified
BigDecimal input with specified scale |
static int |
getDecimal9FromBigDecimal(BigDecimal input,
int scale)
Returns unsigned int value taken from specified
BigDecimal input with specified scale. |
static int |
getDefaultPrecision(TypeProtos.MinorType minorType,
int defaultPrecision)
Returns default precision for specified
TypeProtos.MinorType
or returns specified defaultPrecision if TypeProtos.MinorType isn't
TypeProtos.MinorType.INT or TypeProtos.MinorType.BIGINT . |
static int |
getMaxBytesSizeForPrecision(int precision)
Returns max length of byte array, required to store value with specified precision.
|
static void |
getSparseFromBigDecimal(BigDecimal input,
io.netty.buffer.ByteBuf data,
int startIndex,
int scale,
int nDecimalDigits)
Function converts the BigDecimal and stores it in out internal sparse representation
|
static boolean |
isObsoleteDecimalType(TypeProtos.MinorType minorType)
Checks that specified decimal minorType is obsolete.
|
static int |
roundUp(int ndigits)
Given the number of actual digits this function returns the
number of indexes it will occupy in the array of integers
which are stored in base 1 billion
|
static BigDecimal |
sqrt(BigDecimal in,
int scale)
Calculates and returns square root for specified BigDecimal
with specified number of digits alter decimal point.
|
public static final int MAX_DIGITS
public static final int MAX_DIGITS_INT
public static final int MAX_DIGITS_BIGINT
public static final int DIGITS_BASE
public static final int INTEGER_SIZE
public static int roundUp(int ndigits)
public static BigDecimal getBigDecimalFromSparse(DrillBuf data, int startIndex, int nDecimalDigits, int scale)
public static BigDecimal getBigDecimalFromDrillBuf(DrillBuf bytebuf, int start, int length, int scale)
BigInteger
.public static BigDecimal getBigDecimalFromDrillBuf(io.netty.buffer.ByteBuf data, int startIndex, int nDecimalDigits, int scale, boolean truncateScale)
public static BigDecimal getBigDecimalFromDense(DrillBuf data, int startIndex, int nDecimalDigits, int scale, int maxPrecision, int width)
public static void getSparseFromBigDecimal(BigDecimal input, io.netty.buffer.ByteBuf data, int startIndex, int scale, int nDecimalDigits)
public static long getDecimal18FromBigDecimal(BigDecimal input, int scale)
BigDecimal
input with specified scaleinput
- BigDecimal
with desired valuescale
- scale of the valueBigDecimal
public static int getDecimal9FromBigDecimal(BigDecimal input, int scale)
BigDecimal
input with specified scale.input
- BigDecimal
with desired valuescale
- scale of the valueBigDecimal
public static BigDecimal getBigDecimalFromPrimitiveTypes(int input, int scale)
BigDecimal
value created from specified integer value with specified scale.input
- integer value to use for creating of BigDecimal
scale
- scale for resulting BigDecimal
BigDecimal
valuepublic static BigDecimal getBigDecimalFromPrimitiveTypes(long input, int scale)
BigDecimal
value created from specified long value with specified scale.input
- long value to use for creating of BigDecimal
scale
- scale for resulting BigDecimal
BigDecimal
valuepublic static int compareVarLenBytes(DrillBuf left, int leftStart, int leftEnd, int leftScale, DrillBuf right, int rightStart, int rightEnd, int rightScale, boolean absCompare)
left
- left value Drill bufferleftStart
- start offset of left valueleftEnd
- end offset of left valueleftScale
- scale of left valueright
- right value Drill bufferrightStart
- start offset of right valuerightEnd
- end offset of right valuerightScale
- scale of right valueabsCompare
- comparison of absolute values is done iff this is truepublic static int compareVarLenBytes(DrillBuf left, int leftStart, int leftEnd, int leftScale, byte[] right, int rightScale, boolean absCompare)
left
- left value Drill bufferleftStart
- start offset of left valueleftEnd
- end offset of left valueleftScale
- scale of left valueright
- right value byte arrayrightScale
- scale of right valueabsCompare
- comparison of absolute values is done iff this is truepublic static int getMaxBytesSizeForPrecision(int precision)
precision
- the precision of valuepublic static BigDecimal sqrt(BigDecimal in, int scale)
in
- BigDecimal which square root should be calculatedscale
- number of digits alter decimal point in the result value.public static boolean isObsoleteDecimalType(TypeProtos.MinorType minorType)
minorType
- type to checkpublic static int getDefaultPrecision(TypeProtos.MinorType minorType, int defaultPrecision)
TypeProtos.MinorType
or returns specified defaultPrecision if TypeProtos.MinorType
isn't
TypeProtos.MinorType.INT
or TypeProtos.MinorType.BIGINT
.minorType
- type wich precision should be receiveddefaultPrecision
- default value for precisionTypeProtos.MinorType
public static void checkValueOverflow(BigDecimal value, int desiredPrecision, int desiredScale)
desiredPrecision
precision and desiredScale
scale.
Otherwise, the exception is thrown.value
- BigDecimal value to checkdesiredPrecision
- precision for the resulting valuedesiredScale
- scale for the resulting valueCopyright © 1970 The Apache Software Foundation. All rights reserved.