public final class HiveDecimalWritable extends FastHiveDecimal implements org.apache.hadoop.io.WritableComparable<HiveDecimalWritable>
------------------------------------- Version 2 ------------------------------------------------
This is the 2nd major version of HiveDecimalWritable called V2. The previous version has been renamed to HiveDecimalWritableV1 and is kept as a test and behavior reference.
For good performance we do not represent the decimal using a byte array containing BigInteger bytes like the previous version V1 did. Instead V2 HiveDecimalWritable is is a private subclass of the same fast decimal class also used by HiveDecimal. So it stores the decimal value directly.
Many of the methods of HiveDecimal have been added to HiveDecimalWritable in V2 so code can modify the decimal instead of calling getHiveDecimal(), doing operations on HiveDecimal, and then setting HiveDecimalWritable back to the result.
Operations that modify have a prefix of "mutate" in their name. For example mutateAdd is used instead of the immutable operation add in HiveDecimal that returns a new decimal object.
This should have much better performance.
The original V1 public methods and fields are annotated with @HiveDecimalWritableVersionV1; new public methods and fields are annotated with @HiveDecimalWritableVersionV2.
FastHiveDecimal.FastCheckPrecisionScaleStatus
Modifier and Type | Field and Description |
---|---|
static int |
DECIMAL64_DECIMAL_DIGITS |
FAST_SCRATCH_BUFFER_LEN_BIG_INTEGER_BYTES, FAST_SCRATCH_BUFFER_LEN_SERIALIZATION_UTILS_READ, FAST_SCRATCH_BUFFER_LEN_TO_BYTES, FAST_SCRATCH_LONGS_LEN, fast0, fast1, fast2, fastIntegerDigitCount, fastScale, fastSerializationScale, fastSignum, SCRATCH_LONGS_LEN_FAST_SERIALIZATION_UTILS_WRITE, STRING_ENFORCE_PRECISION_OUT_OF_RANGE, STRING_ENFORCE_SCALE_LESS_THAN_EQUAL_PRECISION, STRING_ENFORCE_SCALE_OUT_OF_RANGE
Constructor and Description |
---|
HiveDecimalWritable()
Create a decimal writable with no current value (i.e.
|
HiveDecimalWritable(byte[] bigIntegerBytes,
int scale)
Create a decimal writable with an initial value from BigInteger bytes and a specified scale.
|
HiveDecimalWritable(HiveDecimal value)
Create a decimal writable with an initial value from a HiveDecimal.
|
HiveDecimalWritable(HiveDecimalWritable writable)
Create a decimal writable with an initial value from another decimal writable.
|
HiveDecimalWritable(long longValue)
Create a decimal writable with an initial value from a long with scale 0.
|
HiveDecimalWritable(String string)
Create a decimal writable with an initial value from a String.
|
Modifier and Type | Method and Description |
---|---|
int |
bigIntegerBytes(long[] scratchLongs,
byte[] scratchBuffer) |
byte[] |
bigIntegerBytesCopy(long[] scratchLongs,
byte[] scratchBuffer)
Allocate scratchLongs with HiveDecimal.SCRATCH_LONGS_LEN longs.
|
int |
bigIntegerBytesInternalScratch()
Returns the length of the decimal converted to bytes.
|
byte[] |
bigIntegerBytesInternalScratchBuffer()
Returns the scratch array containing the result after a call to bigIntegerBytesInternalScratch.
|
byte |
byteValue() |
int |
compareTo(HiveDecimal dec) |
static int |
compareTo(HiveDecimal dec,
HiveDecimalWritable writable) |
int |
compareTo(HiveDecimalWritable writable) |
void |
deserialize64(long decimal64Long,
int scale) |
double |
doubleValue() |
static HiveDecimalWritable |
enforcePrecisionScale(HiveDecimalWritable writable,
int precision,
int scale) |
boolean |
equals(Object other) |
float |
floatValue() |
static long |
getDecimal64AbsMax(int precision) |
HiveDecimal |
getHiveDecimal()
Returns a HiveDecimal for the writable's current value.
|
HiveDecimal |
getHiveDecimal(int maxPrecision,
int maxScale)
Get a HiveDecimal instance from the writable and constraint it with maximum precision/scale.
|
byte[] |
getInternalStorage() |
int |
getScale() |
int |
hashCode() |
int |
intValue() |
boolean |
isByte() |
boolean |
isInt() |
boolean |
isLong() |
static boolean |
isPrecisionDecimal64(int precision) |
boolean |
isSet()
Does this writable have a current value?
|
boolean |
isShort() |
boolean |
isValid() |
long |
longValue() |
void |
mutateAbs() |
void |
mutateAdd(HiveDecimal dec) |
void |
mutateAdd(HiveDecimalWritable decWritable) |
void |
mutateDivide(HiveDecimal dec) |
void |
mutateDivide(HiveDecimalWritable decWritable) |
boolean |
mutateEnforcePrecisionScale(int precision,
int scale) |
void |
mutateFractionPortion() |
void |
mutateIntegerPortion() |
void |
mutateMultiply(HiveDecimal dec) |
void |
mutateMultiply(HiveDecimalWritable decWritable) |
void |
mutateNegate() |
void |
mutateRemainder(HiveDecimal dec) |
void |
mutateRemainder(HiveDecimalWritable decWritable) |
void |
mutateScaleByPowerOfTen(int power) |
void |
mutateSetScale(int roundingPoint,
int roundingMode) |
void |
mutateSubtract(HiveDecimal dec) |
void |
mutateSubtract(HiveDecimalWritable decWritable) |
int |
newFasterHashCode() |
int |
precision() |
int |
rawPrecision() |
void |
readFields(DataInput in)
Standard Writable method that deserialize the fields of this object from a DataInput.
|
int |
scale() |
boolean |
serializationUtilsRead(InputStream inputStream,
int scale,
byte[] scratchBytes)
See the comments for HiveDecimal.serializationUtilsRead.
|
boolean |
serializationUtilsWrite(OutputStream outputStream,
long[] scratchLongs)
See the comments for HiveDecimal.serializationUtilsWrite.
|
long |
serialize64(int scale) |
void |
set(byte[] bigIntegerBytes,
int scale)
Set a decimal writable's value from BigInteger bytes and a specified scale.
|
void |
set(HiveDecimal value)
Set the writable's current value to a HiveDecimal's value.
|
void |
set(HiveDecimal value,
int maxPrecision,
int maxScale)
Set the writable's current value to a HiveDecimal's value with a specified precision / scale
enforced.
|
void |
set(HiveDecimalWritable writable)
Set the writable's current value to the value in a another decimal writable.
|
void |
set(HiveDecimalWritable writable,
int maxPrecision,
int maxScale)
Set the writable's current value to a writable's value with a specified precision / scale
enforced.
|
void |
setFromBigIntegerBytesAndScale(byte[] bigIntegerBytes,
int scale)
Set the writable's current value to the signed value from BigInteger bytes and a specified
scale.
|
void |
setFromBigIntegerBytesAndScale(byte[] bigIntegerBytes,
int offset,
int length,
int scale) |
void |
setFromBytes(byte[] bytes,
int offset,
int length)
Set the writable's current value to the decimal in a UTF-8 byte slice.
|
void |
setFromBytes(byte[] bytes,
int offset,
int length,
boolean trimBlanks) |
void |
setFromDigitsOnlyBytesWithScale(boolean isNegative,
byte[] bytes,
int offset,
int length,
int scale)
Set the writable's current value to the decimal digits only in a UTF-8 byte slice, a sign
flag, and a scale.
|
void |
setFromDouble(double doubleValue)
Set a decimal writable's value to a doubles value.
|
void |
setFromLong(long longValue)
Set a decimal writable's value to a long's value with scale 0.
|
void |
setFromLongAndScale(long longValue,
int scale)
Set the writable's current value to the long's value at a specified
scale.
|
short |
shortValue() |
int |
signum() |
int |
toBytes(byte[] scratchBuffer) |
int |
toDigitsOnlyBytes(byte[] scratchBuffer) |
int |
toFormatBytes(int formatScale,
byte[] scratchBuffer) |
String |
toFormatString(int formatScale) |
String |
toString() |
String |
toString(byte[] scratchBuffer) |
void |
write(DataOutput out)
Standard Writable method that serialize the fields of this object to a DataOutput.
|
void |
write(DataOutput out,
long[] scratchLongs,
byte[] scratchBuffer)
A variation of the standard Writable method that serialize the fields of this object to a
DataOutput with scratch buffers for good performance.
|
fastAbs, fastAdd, fastBigDecimalValue, fastBigIntegerBytes, fastBigIntegerBytesScaled, fastBigIntegerValue, fastByteValueClip, fastCheckPrecisionScale, fastCompareTo, fastCompareTo, fastDeserialize64, fastDivide, fastDoubleValue, fastEnforcePrecisionScale, fastEquals, fastFloatValue, fastFractionPortion, fastHashCode, fastIntegerDigitCount, fastIntegerPortion, fastIntValueClip, fastIsByte, fastIsInt, fastIsLong, fastIsShort, fastIsValid, fastLongValueClip, fastMultiply, fastNegate, fastNewFasterHashCode, fastPow, fastRaiseInvalidException, fastRaiseInvalidException, fastRawPrecision, fastRemainder, fastReset, fastRound, fastRoundingModeToString, fastScale, fastScaleByPowerOfTen, fastSerializationScale, fastSerializationUtilsRead, fastSerializationUtilsWrite, fastSerialize64, fastSet, fastSet, fastSetFromBigDecimal, fastSetFromBigInteger, fastSetFromBigIntegerAndScale, fastSetFromBigIntegerBytesAndScale, fastSetFromBytes, fastSetFromDigitsOnlyBytesAndScale, fastSetFromDouble, fastSetFromFloat, fastSetFromInt, fastSetFromLong, fastSetFromLongAndScale, fastSetFromString, fastSetSerializationScale, fastShortValueClip, fastSignum, fastSqlPrecision, fastSubtract, fastToBytes, fastToDigitsOnlyBytes, fastToDigitsOnlyString, fastToFormatBytes, fastToFormatString, fastToFormatString, fastToString, fastToString, fastUpdatePrecisionScale, isAllZeroesBelow
@HiveDecimalWritableVersionV2 public static final int DECIMAL64_DECIMAL_DIGITS
@HiveDecimalWritableVersionV1 public HiveDecimalWritable()
@HiveDecimalWritableVersionV1 public HiveDecimalWritable(String string)
If the conversion from String to decimal is successful, isSet() will return true.
@HiveDecimalWritableVersionV1 public HiveDecimalWritable(byte[] bigIntegerBytes, int scale)
If the conversion to decimal is successful, isSet() will return true.
@HiveDecimalWritableVersionV1 public HiveDecimalWritable(HiveDecimalWritable writable)
If the supplied writable has a value, isSet() will return true.
@HiveDecimalWritableVersionV1 public HiveDecimalWritable(HiveDecimal value)
Afterwards, the isSet() method will return true, unless value is null.
@HiveDecimalWritableVersionV1 public HiveDecimalWritable(long longValue)
Afterwards, the isSet() method will return true.
@HiveDecimalWritableVersionV1 public void set(HiveDecimal value)
Afterwards, the isSet() method will return true, unless value is null.
@HiveDecimalWritableVersionV1 public void set(HiveDecimal value, int maxPrecision, int maxScale)
Afterwards, the isSet() method will return true, unless value is null or value didn't fit within maxPrecision / maxScale.
@HiveDecimalWritableVersionV1 public void set(HiveDecimalWritable writable)
If the supplied writable has a value, isSet() will return true.
@HiveDecimalWritableVersionV1 public void set(byte[] bigIntegerBytes, int scale)
If the conversion to decimal is successful, isSet() will return true.
@HiveDecimalWritableVersionV2 public void set(HiveDecimalWritable writable, int maxPrecision, int maxScale)
The isSet() method will return true, unless value is null or value didn't fit within maxPrecision / maxScale.
@HiveDecimalWritableVersionV2 public void setFromLong(long longValue)
Afterwards, the isSet() method will return true since all long values fit in a decimal.
@HiveDecimalWritableVersionV2 public void setFromDouble(double doubleValue)
Afterwards, the isSet() method will return true if the double to decimal conversion was successful.
@HiveDecimalWritableVersionV2 public void setFromBytes(byte[] bytes, int offset, int length)
Afterwards, the isSet() method will return true, unless byte slice could not be converted.
@HiveDecimalWritableVersionV2 public void setFromBytes(byte[] bytes, int offset, int length, boolean trimBlanks)
@HiveDecimalWritableVersionV2 public void setFromDigitsOnlyBytesWithScale(boolean isNegative, byte[] bytes, int offset, int length, int scale)
Afterwards, the isSet() method will return true, unless byte slice etc could not be converted.
@HiveDecimalWritableVersionV2 public void setFromBigIntegerBytesAndScale(byte[] bigIntegerBytes, int scale)
Afterwards, the isSet() method will return true, unless conversion failed.
@HiveDecimalWritableVersionV2 public void setFromBigIntegerBytesAndScale(byte[] bigIntegerBytes, int offset, int length, int scale)
@HiveDecimalWritableVersionV2 public void setFromLongAndScale(long longValue, int scale)
Afterwards, the isSet() method will return true, unless conversion failed.
@HiveDecimalWritableVersionV2 public boolean isSet()
A return of false means a current value wasn't set, or an operation like mutateAdd overflowed, or a set* method couldn't convert the input value, etc.
@HiveDecimalWritableVersionV1 public HiveDecimal getHiveDecimal()
Returns null if the writable isn't set.
@HiveDecimalWritableVersionV1 public HiveDecimal getHiveDecimal(int maxPrecision, int maxScale)
maxPrecision
- maximum precisionmaxScale
- maximum scale@HiveDecimalWritableVersionV1 public void readFields(DataInput in) throws IOException
readFields
in interface org.apache.hadoop.io.Writable
IOException
@HiveDecimalWritableVersionV1 public void write(DataOutput out) throws IOException
write
in interface org.apache.hadoop.io.Writable
IOException
@HiveDecimalWritableVersionV2 public void write(DataOutput out, long[] scratchLongs, byte[] scratchBuffer) throws IOException
Allocate scratchLongs with HiveDecimal.SCRATCH_LONGS_LEN longs. And, allocate scratch buffer with HiveDecimal.SCRATCH_BUFFER_LEN_BIG_INTEGER_BYTES bytes.
IOException
@HiveDecimalWritableVersionV2 public boolean serializationUtilsRead(InputStream inputStream, int scale, byte[] scratchBytes) throws IOException
IOException
@HiveDecimalWritableVersionV2 public boolean serializationUtilsWrite(OutputStream outputStream, long[] scratchLongs) throws IOException
IOException
@HiveDecimalWritableVersionV2 public static boolean isPrecisionDecimal64(int precision)
@HiveDecimalWritableVersionV2 public static long getDecimal64AbsMax(int precision)
@HiveDecimalWritableVersionV2 public void deserialize64(long decimal64Long, int scale)
@HiveDecimalWritableVersionV2 public long serialize64(int scale)
@HiveDecimalWritableVersionV2 public boolean isValid()
@HiveDecimalWritableVersionV2 public int bigIntegerBytesInternalScratch()
@HiveDecimalWritableVersionV2 public byte[] bigIntegerBytesInternalScratchBuffer()
@HiveDecimalWritableVersionV2 public byte[] bigIntegerBytesCopy(long[] scratchLongs, byte[] scratchBuffer)
@HiveDecimalWritableVersionV2 public int bigIntegerBytes(long[] scratchLongs, byte[] scratchBuffer)
@HiveDecimalWritableVersionV2 public int signum()
@HiveDecimalWritableVersionV2 public int precision()
@HiveDecimalWritableVersionV2 public int rawPrecision()
@HiveDecimalWritableVersionV2 public int scale()
@HiveDecimalWritableVersionV2 public boolean isByte()
@HiveDecimalWritableVersionV2 public byte byteValue()
@HiveDecimalWritableVersionV2 public boolean isShort()
@HiveDecimalWritableVersionV2 public short shortValue()
@HiveDecimalWritableVersionV2 public boolean isInt()
@HiveDecimalWritableVersionV2 public int intValue()
@HiveDecimalWritableVersionV2 public boolean isLong()
@HiveDecimalWritableVersionV2 public long longValue()
@HiveDecimalWritableVersionV2 public float floatValue()
@HiveDecimalWritableVersionV2 public double doubleValue()
@HiveDecimalWritableVersionV2 public void mutateAbs()
@HiveDecimalWritableVersionV2 public void mutateNegate()
@HiveDecimalWritableVersionV2 public void mutateAdd(HiveDecimalWritable decWritable)
@HiveDecimalWritableVersionV2 public void mutateAdd(HiveDecimal dec)
@HiveDecimalWritableVersionV2 public void mutateSubtract(HiveDecimalWritable decWritable)
@HiveDecimalWritableVersionV2 public void mutateSubtract(HiveDecimal dec)
@HiveDecimalWritableVersionV2 public void mutateMultiply(HiveDecimalWritable decWritable)
@HiveDecimalWritableVersionV2 public void mutateMultiply(HiveDecimal dec)
@HiveDecimalWritableVersionV2 public void mutateDivide(HiveDecimalWritable decWritable)
@HiveDecimalWritableVersionV2 public void mutateDivide(HiveDecimal dec)
@HiveDecimalWritableVersionV2 public void mutateRemainder(HiveDecimalWritable decWritable)
@HiveDecimalWritableVersionV2 public void mutateRemainder(HiveDecimal dec)
@HiveDecimalWritableVersionV2 public void mutateScaleByPowerOfTen(int power)
@HiveDecimalWritableVersionV2 public void mutateFractionPortion()
@HiveDecimalWritableVersionV2 public void mutateIntegerPortion()
@HiveDecimalWritableVersionV1 public int compareTo(HiveDecimalWritable writable)
compareTo
in interface Comparable<HiveDecimalWritable>
@HiveDecimalWritableVersionV2 public int compareTo(HiveDecimal dec)
@HiveDecimalWritableVersionV2 public static int compareTo(HiveDecimal dec, HiveDecimalWritable writable)
@HiveDecimalWritableVersionV2 public int toBytes(byte[] scratchBuffer)
@HiveDecimalWritableVersionV1 public String toString()
toString
in class FastHiveDecimal
@HiveDecimalWritableVersionV2 public String toString(byte[] scratchBuffer)
@HiveDecimalWritableVersionV2 public String toFormatString(int formatScale)
@HiveDecimalWritableVersionV2 public int toFormatBytes(int formatScale, byte[] scratchBuffer)
@HiveDecimalWritableVersionV2 public int toDigitsOnlyBytes(byte[] scratchBuffer)
@HiveDecimalWritableVersionV1 public boolean equals(Object other)
@HiveDecimalWritableVersionV2 public int newFasterHashCode()
@HiveDecimalWritableVersionV1 public int hashCode()
@HiveDecimalWritableVersionV1 public byte[] getInternalStorage()
@HiveDecimalWritableVersionV1 public int getScale()
@HiveDecimalWritableVersionV2 public void mutateSetScale(int roundingPoint, int roundingMode)
@HiveDecimalWritableVersionV2 public boolean mutateEnforcePrecisionScale(int precision, int scale)
@HiveDecimalWritableVersionV1 public static HiveDecimalWritable enforcePrecisionScale(HiveDecimalWritable writable, int precision, int scale)
Copyright © 2021 The Apache Software Foundation. All rights reserved.