private static Decimal convertToThriftDecimal(HiveDecimal d) { return DecimalUtils.getDecimal(ByteBuffer.wrap(d.unscaledValue().toByteArray()), (short) d.scale()); }
private Decimal convertToThriftDecimal(HiveDecimal d) { return new Decimal(ByteBuffer.wrap(d.unscaledValue().toByteArray()), (short)d.scale()); }
private void parseDecimalColumn(int column) { loaded[column] = true; Object fieldData = rowInspector.getStructFieldData(rowData, structFields[column]); if (fieldData == null) { nulls[column] = true; } else { Object fieldValue = ((PrimitiveObjectInspector) fieldInspectors[column]).getPrimitiveJavaObject(fieldData); checkState(fieldValue != null, "fieldValue should not be null"); HiveDecimal decimal = (HiveDecimal) fieldValue; DecimalType columnType = (DecimalType) types[column]; BigInteger unscaledDecimal = rescale(decimal.unscaledValue(), decimal.scale(), columnType.getScale()); if (columnType.isShort()) { longs[column] = unscaledDecimal.longValue(); } else { slices[column] = Decimals.encodeUnscaledValue(unscaledDecimal); } nulls[column] = false; } }
BigInteger bigInteger = writable.getHiveDecimal().unscaledValue(); if (hiveScale < scale) { BigInteger multiplicand = new BigInteger("1" + join("", Collections.nCopies(scale - hiveScale, "0")));
private Binary decimalToBinary(final HiveDecimal hiveDecimal, final DecimalTypeInfo decimalTypeInfo) { int prec = decimalTypeInfo.precision(); int scale = decimalTypeInfo.scale(); byte[] decimalBytes = hiveDecimal.setScale(scale).unscaledValue().toByteArray(); // Estimated number of bytes needed. int precToBytes = ParquetHiveSerDe.PRECISION_TO_BYTE_COUNT[prec - 1]; if (precToBytes == decimalBytes.length) { // No padding needed. return Binary.fromByteArray(decimalBytes); } byte[] tgt = new byte[precToBytes]; if (hiveDecimal.signum() == -1) { // For negative number, initializing bits to 1 for (int i = 0; i < precToBytes; i++) { tgt[i] |= 0xFF; } } System.arraycopy(decimalBytes, 0, tgt, precToBytes - decimalBytes.length, decimalBytes.length); // Padding leading zeroes/ones. return Binary.fromByteArray(tgt); } }
@Override void write(Object obj) throws IOException { super.write(obj); if (obj != null) { HiveDecimal decimal = ((HiveDecimalObjectInspector) inspector).getPrimitiveJavaObject(obj); if (decimal == null) { return; } SerializationUtils.writeBigInteger(valueStream, decimal.unscaledValue()); scaleStream.write(decimal.scale()); indexStatistics.updateDecimal(decimal); if (createBloomFilter) { bloomFilter.addString(decimal.toString()); } } }
Assert.assertEquals(bigInteger, dec.unscaledValue());
HiveDecimalWritable writable = (HiveDecimalWritable) actualValue; BigInteger rescaledValue = rescale(writable.getHiveDecimal().unscaledValue(), writable.getScale(), decimalType.getScale()); actualValue = new SqlDecimal(rescaledValue, decimalType.getPrecision(), decimalType.getScale());
BigInteger bigInteger = dec.unscaledValue(); int scale = dec.scale();
Assert.assertEquals(bigInteger, dec.unscaledValue()); SerializationUtils.writeBigInteger(outputStream, dec.unscaledValue()); bytes = outputStream.toByteArray();
HiveDecimalWritable writable = (HiveDecimalWritable) actualValue; BigInteger rescaledValue = rescale(writable.getHiveDecimal().unscaledValue(), writable.getScale(), decimalType.getScale()); actualValue = new SqlDecimal(rescaledValue, decimalType.getPrecision(), decimalType.getScale());
public static Buffer getBufferFromDecimal(HiveDecimal dec, int scale) { if (dec == null) { return null; } dec = dec.setScale(scale); return AvroSerdeUtils.getBufferFromBytes(dec.unscaledValue().toByteArray()); }
public static Buffer getBufferFromDecimal(HiveDecimal dec, int scale) { if (dec == null) { return null; } dec = dec.setScale(scale); return AvroSerdeUtils.getBufferFromBytes(dec.unscaledValue().toByteArray()); }
public static Buffer getBufferFromDecimal(HiveDecimal dec, int scale) { if (dec == null) { return null; } dec = dec.setScale(scale); return AvroSerdeUtils.getBufferFromBytes(dec.unscaledValue().toByteArray()); }
public void set(HiveDecimal value) { set(value.unscaledValue().toByteArray(), value.scale()); }
public void set(HiveDecimal value) { set(value.unscaledValue().toByteArray(), value.scale()); }
public void set(HiveDecimal value) { set(value.unscaledValue().toByteArray(), value.scale()); }
public static void writeToByteStream(Decimal128 dec, Output byteStream) { HiveDecimal hd = HiveDecimal.create(dec.toBigDecimal()); LazyBinaryUtils.writeVInt(byteStream, hd.scale()); byte[] bytes = hd.unscaledValue().toByteArray(); LazyBinaryUtils.writeVInt(byteStream, bytes.length); byteStream.write(bytes, 0, bytes.length); }
public static void writeToByteStream(Decimal128 dec, Output byteStream) { HiveDecimal hd = HiveDecimal.create(dec.toBigDecimal()); LazyBinaryUtils.writeVInt(byteStream, hd.scale()); byte[] bytes = hd.unscaledValue().toByteArray(); LazyBinaryUtils.writeVInt(byteStream, bytes.length); byteStream.write(bytes, 0, bytes.length); }
public static void writeToByteStream(Decimal128 dec, Output byteStream) { HiveDecimal hd = HiveDecimal.create(dec.toBigDecimal()); LazyBinaryUtils.writeVInt(byteStream, hd.scale()); byte[] bytes = hd.unscaledValue().toByteArray(); LazyBinaryUtils.writeVInt(byteStream, bytes.length); byteStream.write(bytes, 0, bytes.length); }