Hello all,
I am working on avro logical type decimal, but was not sure what data
has to be provided.
As mentioned in the Avro document,
A decimal logical type annotates Avro bytes or fixed types. The byte
array must contain the two's-complement representation of the unscaled
integer value in big-endian byte order. The scale is fixed, and is
specified using an attribute.
But in code, in Conversions class, I can see that, from a decimal
value, it is forming a ByteArray.
@Override
public BigDecimal fromBytes(ByteBuffer value, Schema schema, LogicalType type) {
int scale = ((LogicalTypes.Decimal) type).getScale();
// always copy the bytes out because BigInteger has no offset/length ctor
byte[] bytes = value.get(new byte[value.remaining()]).array();
return new BigDecimal(new BigInteger(bytes), scale);
}
@Override
public ByteBuffer toBytes(BigDecimal value, Schema schema, LogicalType type) {
int scale = ((LogicalTypes.Decimal) type).getScale();
if (scale != value.scale()) {
throw new AvroTypeException("Cannot encode decimal with scale " +
value.scale() + " as scale " + scale);
}
return ByteBuffer.wrap(value.unscaledValue().toByteArray());
}
but, I find that, nowhere two's-complement representation of the
unscaled integer
value in big-endian byte order is stored in byte array.
Can anyone help me with this?
Thanks,
Indhumathi M