avroOf does not support logical types
I just started using ratatool today and am using it for CaseClass and Avro generation. I believe there's an issue in the way it handles, or fails to handle, logical types in avro.
I'm using java/scala type BigDecimal, which in schema looks like this (newlines added by me for easier reading):
{
"name":"cost",
"type": {
"type":"bytes",
"logicalType":"decimal",
"precision":10,
"scale":2
}
}
Decimal logical type is documented here: https://avro.apache.org/docs/current/spec.html#Logical+Types
What's happening when attempting to use avroOf[MyGenericRecord] is the type pattern match (found in AvroGenerator.scala) hits Schema.Type.BYTES and can generate byte[0].
Later, the AvroCodec, which does honor the BigDecimal logical type, attempts to convert byte[0] into a BigInteger (see https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/Conversions.java#L84), which fails with:
NumberFormatException("Zero length BigInteger")
I feel there's a few options which could be done independently here (I'll PR as I'm able):
- document the current limitation
- add support for common, documented logical types to ratatool. likely these can be done in independent PRs
I'm spending some time on this, and will try to create a PR late next week..!
I see a corresponding problem for { "type": "int", "logicalType": "date" } which gives a java.lang.ClassCastException: java.lang.Integer cannot be cast to org.joda.time.LocalDate.
Yeah I ran into this issue as well while trying to generate data for something with a decimal logical type. This would be super helpful to have.
Ran into the same issue, is there a workaround for this?
Fixed by #691