beam-community / avro_ex

An Avro Library that emphasizes testability and ease of use.
https://hexdocs.pm/avro_ex/AvroEx.html
67 stars 27 forks source link

Can't parse default value of 1 as a double #92

Open larshesel opened 10 months ago

larshesel commented 10 months ago

Passing the following into AvroEx.decode_schema!/1

{
  "type": "record",
  "name": "record0",
  "namespace": "namespace",
  "fields": [
    {
      "name": "double_test",
      "type": "double",
      "default": 1
    }
  ]
}

gives this error:

     ** (AvroEx.Schema.DecodeError) Invalid default in Field<name=double_test> Schema Mismatch: Expected value of double, got 1

Other validators, like the confluence cloud schema validator, validates this and to me it seems reasonable that an value without decimals should be parsed as a double.

With the following "fix" I was able to make AvroEx do as I wanted: https://github.com/beam-community/avro_ex/compare/master...larshesel:avro_ex:larshesel-double-integer-default?expand=1

I'm sure this is not the final solution - if you think this is an actual error I'd love to create a proper PR.

Hanspagh commented 10 months ago

Hi. Thank you for the report, it seems reasonable, and I can't seem to find any documentation mentioning this. If we go down this road I guess we should do the same for the float type. Can you confirm that confluence schema validate behaves the same for floats?

davydog187 commented 5 months ago

Sorry @larshesel I never got around to responding! We should do whatever the Java implementation does. Do you have any further info?