@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; }
/** * A short variation of longValue(). * <p> * This method will return a corrupted value unless isShort() is true. */ @HiveDecimalVersionV1 public short shortValue() { return fastShortValueClip(); }
private long truncate(Timestamp ts, HiveIntervalDayTime idt, Timestamp origin) { long intervalDurationMs = idt.getTotalSeconds() * 1000L + idt.getNanos() / 1000L; long offset = ts.toEpochMilli() % intervalDurationMs - origin.toEpochMilli() % intervalDurationMs; if (offset < 0) { offset += intervalDurationMs; } return ts.toEpochMilli() - offset; }
/** * Create a HiveDecimal object from an int. * */ @HiveDecimalVersionV1 public static HiveDecimal create(int intValue) { HiveDecimal result = new HiveDecimal(); result.fastSetFromInt(intValue); return result; }
/** * Create a HiveDecimal object from a long. * */ @HiveDecimalVersionV1 public static HiveDecimal create(long longValue) { HiveDecimal result = new HiveDecimal(); result.fastSetFromLong(longValue); 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; }
/** * Used to check overflows. This is NOT used in {@link UnsignedInt128} itself * because this overflow semantics is Decimal's. (throws - but not a checked * exception) ArithmeticException if this value is equal to or exceed 10**38. */ public void throwIfExceedsTenToThirtyEight() { if (exceedsTenToThirtyEight()) { SqlMathUtil.throwOverflowException(); } }
/** * 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); }
/** * Throws an exception if the current decimal value is invalid. */ @HiveDecimalVersionV2 public void validate() { if (!fastIsValid()) { fastRaiseInvalidException(); } } }
/** * Return a BigDecimal representing the decimal. The BigDecimal class is able to accurately * represent the decimal. * * NOTE: We are not representing our decimal as BigDecimal now as OldHiveDecimal did, so this * is now slower. * */ @HiveDecimalVersionV1 public BigDecimal bigDecimalValue() { return fastBigDecimalValue(); }
/** * 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(); }
/** * Return the long value of a decimal. * <p> * This method will return a corrupted value unless isLong() is true. */ @HiveDecimalVersionV1 public long longValue() { return fastLongValueClip(); }
/** * Return a double representing the decimal. Due the limitations of double, some values will not * be accurate. * */ @HiveDecimalVersionV1 public double doubleValue() { return fastDoubleValue(); }
/** * Returns the scale of the decimal. Range 0 .. MAX_SCALE. * */ @HiveDecimalVersionV1 public int scale() { return fastScale(); }
/** * Return a float representing the decimal. Due the limitations of float, some values will not * be accurate. * */ @HiveDecimalVersionV1 public float floatValue() { return fastFloatValue(); }
@HiveDecimalVersionV2 public String toFormatString(int formatScale, byte[] scratchBuffer) { return fastToFormatString( formatScale, scratchBuffer); }
@HiveDecimalVersionV2 public String toDigitsOnlyString() { return fastToDigitsOnlyString(); }
@HiveDecimalVersionV1 @Override public int compareTo(HiveDecimal dec) { return fastCompareTo(dec); }
/** * A byte variation of longValue() * <p> * This method will return a corrupted value unless isByte() is true. */ @HiveDecimalVersionV1 public byte byteValue() { return fastByteValueClip(); }