julianpeeters / avrohugger

Generate Scala case class definitions from Avro schemas
Apache License 2.0
202 stars 120 forks source link

Support for `decimal` logical type. #86

Closed raulraja closed 6 years ago

raulraja commented 6 years ago

WIP

The following PR brings support for the decimal logical type available since avro 1.8.x An idl file like this one:

@namespace("example.idl")

protocol DecimalIDL {

  record DecimalIdl {
    decimal(9, 2) dec = 8888.88;
    union {decimal(9, 2), null} maybeDec = 9999.99;
  }

}

generates:

/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY */
package example.idl

case class DecimalIdl(dec: BigDecimal = scala.math.BigDecimal("8888.88"), maybeDec: Option[BigDecimal] = Some(scala.math.BigDecimal("9999.99")))
raulraja commented 6 years ago

@julianpeeters Let me know how this should be tested besides the ones I added following the current pattern if you think it needs more coverage than that.

julianpeeters commented 6 years ago

@raulraja Looking good! Can we confirm that the generated results compile by adding add a logical.avdl and a logical.avsc (with a field and field-with-default-value for each logical type we support) to this dir, so we can test with scripted avrohugger/GenericSerializationTests?

That way we can confirm that the