Skip to content

avroOf does not support logical types #178

Closed
@drobert

Description

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):

  1. document the current limitation
  2. add support for common, documented logical types to ratatool. likely these can be done in independent PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions