private static BigDecimal readBigDecimal(HiveDecimalWritable hiveDecimalWritable) { HiveDecimal hiveDecimal = hiveDecimalWritable.getHiveDecimal(); return hiveDecimal.bigDecimalValue(); }
protected HiveDecimal trunc(HiveDecimal input, int scale) { BigDecimal bigDecimal = trunc(input.bigDecimalValue(), scale); return HiveDecimal.create(bigDecimal); }
protected HiveDecimal trunc(HiveDecimal input, int scale) { BigDecimal bigDecimal = trunc(input.bigDecimalValue(), scale); return HiveDecimal.create(bigDecimal); }
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { ((NullableVarDecimalVector) outputVV).getMutator() .setSafe( outputIndex, ((HiveDecimalObjectInspector) oi) .getPrimitiveJavaObject(hiveFieldValue).bigDecimalValue() .setScale(outputVV.getField().getScale(), RoundingMode.HALF_UP)); } }
xDecimalValue = ((HiveDecimalObjectInspector) argumentOIs[0]) .getPrimitiveJavaObject(arg0); resultText.set(numberFormat.format(xDecimalValue.bigDecimalValue())); break; case BYTE:
/** * Divide the target object by right, and scale the result to newScale. * * This uses HiveDecimal to get a correct answer with the same rounding * behavior as HiveDecimal, but it is expensive. * * In the future, a native implementation could be faster. */ public void divideDestructive(Decimal128 right, short newScale) { HiveDecimal rightHD = HiveDecimal.create(right.toBigDecimal()); HiveDecimal thisHD = HiveDecimal.create(this.toBigDecimal()); HiveDecimal result = thisHD.divide(rightHD); /* If the result is null, throw an exception. This can be caught * by calling code in the vectorized code path and made to yield * a SQL NULL value. */ if (result == null) { throw new ArithmeticException("null divide result"); } this.update(result.bigDecimalValue().toPlainString(), newScale); this.unscaledValue.throwIfExceedsTenToThirtyEight(); }
xDecimalValue = ((HiveDecimalObjectInspector) argumentOIs[0]) .getPrimitiveJavaObject(arg0); resultText.set(numberFormat.format(xDecimalValue.bigDecimalValue())); break; case BYTE:
/** * Performs multiplication, changing the scale of this object to the specified * value. * * @param right * right operand. this object is not modified. * @param newScale * scale of the result. must be 0 or positive. */ public void multiplyDestructive(Decimal128 right, short newScale) { HiveDecimal rightHD = HiveDecimal.create(right.toBigDecimal()); HiveDecimal thisHD = HiveDecimal.create(this.toBigDecimal()); HiveDecimal result = thisHD.multiply(rightHD); /* If the result is null, throw an exception. This can be caught * by calling code in the vectorized code path and made to yield * a SQL NULL value. */ if (result == null) { throw new ArithmeticException("null multiply result"); } this.update(result.bigDecimalValue().toPlainString(), newScale); this.unscaledValue.throwIfExceedsTenToThirtyEight(); }
static Object convertPrimitive(Object val, PrimitiveObjectInspector poi) { switch (poi.getPrimitiveCategory()) { // Save char/varchar as string case CHAR: return ((HiveChar) poi.getPrimitiveJavaObject(val)).getPaddedValue(); case VARCHAR: return ((HiveVarchar) poi.getPrimitiveJavaObject(val)).toString(); case DECIMAL: return ((HiveDecimal) poi.getPrimitiveJavaObject(val)).bigDecimalValue(); default: return poi.getPrimitiveJavaObject(val); } }
value = ((HiveDecimal) value).bigDecimalValue(); } else if (value instanceof Decimal128) { value = ((Decimal128) value).toBigDecimal();
break; case DECIMAL: result = ((HiveDecimal)o).bigDecimalValue(); break; case CHAR:
value = ((HiveDecimal) value).bigDecimalValue(); } else if (value instanceof Decimal128) { value = ((Decimal128) value).toBigDecimal();
final BigDecimal value = ((HiveDecimal)val).bigDecimalValue(); final NullableDecimal9Vector v = ((NullableDecimal9Vector) vector); final Decimal9Holder holder = new Decimal9Holder(); final BigDecimal value = ((HiveDecimal)val).bigDecimalValue(); final NullableDecimal18Vector v = ((NullableDecimal18Vector) vector); final Decimal18Holder holder = new Decimal18Holder(); needSpace, managedBuffer.capacity())); final BigDecimal value = ((HiveDecimal)val).bigDecimalValue(); final NullableDecimal28SparseVector v = ((NullableDecimal28SparseVector) vector); final Decimal28SparseHolder holder = new Decimal28SparseHolder(); String.format("Not sufficient space in given managed buffer. Need %d bytes, buffer has %d bytes", needSpace, managedBuffer.capacity())); final BigDecimal value = ((HiveDecimal)val).bigDecimalValue(); final NullableDecimal38SparseVector v = ((NullableDecimal38SparseVector) vector); final Decimal38SparseHolder holder = new Decimal38SparseHolder(); final BigDecimal value = ((HiveDecimal) val).bigDecimalValue() .setScale(vector.getField().getScale(), RoundingMode.HALF_UP); final NullableVarDecimalVector v = ((NullableVarDecimalVector) vector);
d6.update(hd1.bigDecimalValue()); assertEquals(hd1.toString(), d6.getHiveDecimalString()); d7.update(hd2.bigDecimalValue()); assertEquals(hd2.toString(), d7.getHiveDecimalString()); d8.update(hd3.bigDecimalValue()); assertEquals(hd3.toString(), d8.getHiveDecimalString()); d9.update(hd4.bigDecimalValue()); assertEquals(hd4.toString(), d9.getHiveDecimalString()); d10.update(hd5.bigDecimalValue()); assertEquals(hd5.toString(), d10.getHiveDecimalString()); d11.update(hd6.bigDecimalValue()); assertEquals(hd6.toString(), d11.getHiveDecimalString());
&& lowValue != null && lowValue.getUnscaled() != null) { HiveDecimal maxHiveDec = HiveDecimal.create(new BigInteger(highValue.getUnscaled()), highValue.getScale()); BigDecimal maxVal = maxHiveDec == null ? null : maxHiveDec.bigDecimalValue(); HiveDecimal minHiveDec = HiveDecimal.create(new BigInteger(lowValue.getUnscaled()), lowValue.getScale()); BigDecimal minVal = minHiveDec == null ? null : minHiveDec.bigDecimalValue();
&& lowValue != null && lowValue.getUnscaled() != null) { HiveDecimal maxHiveDec = HiveDecimal.create(new BigInteger(highValue.getUnscaled()), highValue.getScale()); BigDecimal maxVal = maxHiveDec == null ? null : maxHiveDec.bigDecimalValue(); HiveDecimal minHiveDec = HiveDecimal.create(new BigInteger(lowValue.getUnscaled()), lowValue.getScale()); BigDecimal minVal = minHiveDec == null ? null : minHiveDec.bigDecimalValue();
value = ((HiveDecimal) value).bigDecimalValue(); } else if (value instanceof HiveChar) { value = ((HiveChar) value).getValue().trim();
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { DecimalUtility.writeBigDecimalToArrowBuf(((HiveDecimalObjectInspector)oi).getPrimitiveJavaObject(hiveFieldValue).bigDecimalValue().setScale(holder.scale, RoundingMode.HALF_UP), holder.buffer, holder.start); ((DecimalVector) outputVV).setSafe(outputIndex, 1, 0, holder.buffer); } }
@Test public void convertDoubleNumberIntoBigDecimalWithoutRounding() { Double input = new Double("0.12345678912345678"); HiveDecimal actual = importHelper.convertNumberIntoHiveDecimal(input); assertEquals(new BigDecimal("0.12345678912345678"), actual.bigDecimalValue()); }
@Test public void convertLongNumberIntoBigDecimalWithoutRounding() { Long input = new Long("20160523112914897"); HiveDecimal actual = importHelper.convertNumberIntoHiveDecimal(input); assertEquals(new BigDecimal("20160523112914897"), actual.bigDecimalValue()); } @Test