/** * Create a HiveDecimal from a FastHiveDecimal object. Used by HiveDecimalWritable. * @param fastDec the value to set * @return new hive decimal */ @HiveDecimalVersionV2 public static HiveDecimal createFromFast(FastHiveDecimal fastDec) { return new HiveDecimal(fastDec); }
@HiveDecimalVersionV2 public byte[] bigIntegerBytes() { long[] scratchLongs = new long[SCRATCH_LONGS_LEN]; byte[] buffer = new byte[SCRATCH_BUFFER_LEN_BIG_INTEGER_BYTES]; final int byteLength = fastBigIntegerBytes( scratchLongs, buffer); return Arrays.copyOfRange(buffer, 0, byteLength); }
@HiveDecimalVersionV2 public String toFormatString(int formatScale, byte[] scratchBuffer) { return fastToFormatString( formatScale, scratchBuffer); }
@HiveDecimalVersionV2 public String toDigitsOnlyString() { return fastToDigitsOnlyString(); }
@HiveDecimalVersionV2 public byte[] bigIntegerBytesScaled(int serializeScale) { long[] scratchLongs = new long[SCRATCH_LONGS_LEN]; byte[] buffer = new byte[SCRATCH_BUFFER_LEN_BIG_INTEGER_BYTES]; int byteLength = fastBigIntegerBytesScaled( serializeScale, scratchLongs, buffer); return Arrays.copyOfRange(buffer, 0, byteLength); }
/** * Returns the number of integer digits in the decimal. * <p> * When the integer portion is zero, this method returns 0. * */ @HiveDecimalVersionV2 public int integerDigitCount() { return fastIntegerDigitCount(); }
@HiveDecimalVersionV2 public int rawPrecision() { return fastRawPrecision(); }
/** * Hash code based on (new) decimal representation. * <p> * Faster than hashCode(). * <p> * Used by map join and other Hive internal purposes where performance is important. * <p> * IMPORTANT: See comments for hashCode(), too. */ @HiveDecimalVersionV2 public int newFasterHashCode() { return fastNewFasterHashCode(); }
@HiveDecimalVersionV2 public static HiveDecimal create( boolean isNegative, byte[] bytes, int offset, int length, int scale) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromDigitsOnlyBytesAndScale( isNegative, bytes, offset, length, scale)) { return null; } return result; }
/** * Return a decimal with only the integer digits. * <p> * Any fractional digits are removed. E.g. 2.083 scale 3 returns as 2 scale 0. * */ @HiveDecimalVersionV2 public HiveDecimal integerPortion() { HiveDecimal result = new HiveDecimal(); result.fastIntegerPortion(); return result; }
/** * Return a decimal with only the fractional digits. * <p> * Zero is returned when there are no fractional digits (i.e. scale is 0). * */ @HiveDecimalVersionV2 public HiveDecimal fractionPortion() { HiveDecimal result = new HiveDecimal(); result.fastFractionPortion(); return result; }
/** * Throws an exception if the current decimal value is invalid. */ @HiveDecimalVersionV2 public void validate() { if (!fastIsValid()) { fastRaiseInvalidException(); } } }
@HiveDecimalVersionV2 public static HiveDecimal createFromBigIntegerBytesAndScale( byte[] bytes, int offset, int length, int scale) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromBigIntegerBytesAndScale( bytes, offset, length, scale)) { return null; } return result; }
/** * Create a HiveDecimal object from a float. * <p> * This method is equivalent to HiveDecimal.create(Float.toString(floatValue)) */ @HiveDecimalVersionV2 public static HiveDecimal create(float floatValue) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromFloat(floatValue)) { return null; } return result; }
/** * Create a HiveDecimal object from a double. * <p> * This method is equivalent to HiveDecimal.create(Double.toString(doubleValue)) */ @HiveDecimalVersionV2 public static HiveDecimal create(double doubleValue) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromDouble(doubleValue)) { return null; } return result; }
/** * Same as the method above, except blanks before and after are tolerated. * @param string the string to parse * @param trimBlanks True specifies leading and trailing blanks are to be ignored. * @return a new hive decimal */ @HiveDecimalVersionV2 public static HiveDecimal create(String string, boolean trimBlanks) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromString( string, trimBlanks)) { return null; } return result; }
/** * Same as the method above, except blanks before and after are tolerated. * */ @HiveDecimalVersionV2 public static HiveDecimal create(byte[] bytes, boolean trimBlanks) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromBytes( bytes, 0, bytes.length, trimBlanks)) { return null; } return result; }
/** * Create a HiveDecimal object from a long with a specified scale. * */ @HiveDecimalVersionV2 public static HiveDecimal create(long longValue, int scale) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromLongAndScale( longValue, scale)) { return null; } return result; }
/** * Same as the method above, except blanks before and after are tolerated. * */ @HiveDecimalVersionV2 public static HiveDecimal create( byte[] bytes, int offset, int length, boolean trimBlanks) { HiveDecimal result = new HiveDecimal(); if (!result.fastSetFromBytes( bytes, offset, length, trimBlanks)) { return null; } return result; }
@HiveDecimalVersionV2 public String toString( byte[] scratchBuffer) { if (fastSerializationScale() != -1) { // Use the serialization scale and format the string with trailing zeroes (or // round the decimal) if necessary. return fastToFormatString( fastSerializationScale(), scratchBuffer); } else { return fastToString(scratchBuffer); } }