[
https://issues.apache.org/jira/browse/AVRO-2858?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17129348#comment-17129348
]
Ryan Skraba commented on AVRO-2858:
-----------------------------------
Unfortunately, the Avro spec doesn't say anything about NaN or Infinity
representations in default values...
It looks like JSON *numbers* don't support these values either in
[RFC7159|https://tools.ietf.org/html/rfc7159#page-6]
The IEEE 754 floating point spec (in Section 5.12) says that they can be
represented as the case insensitive strings nan, snan, inf, infinity (case
insensitive and with an optional +/- sign in front).
When printed as a JSON String, what would we expect a field with a NaN default
to look like?
> SchemaBuilder.GenericDefault withDefault method does not handle Double.NaN
> correctly
> ------------------------------------------------------------------------------------
>
> Key: AVRO-2858
> URL: https://issues.apache.org/jira/browse/AVRO-2858
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.9.2
> Reporter: Gordon Wang
> Priority: Major
>
> Upgraded to Avro 1.9.2 and found when using the withDefault method in
> SchemaBuilder.GenericDefault to set default value for a Double typed field,
> it cannot set Double.NaN correctly, throwing out below error:
> {code}
> Exception in thread "main" org.apache.avro.AvroTypeException: Invalid
> default for field field: "NaN" not a "double"
> at org.apache.avro.Schema.validateDefault(Schema.java:1540)
> at org.apache.avro.Schema.access$500(Schema.java:87)
> at org.apache.avro.Schema$Field.<init>(Schema.java:521)
> at
> org.apache.avro.SchemaBuilder$FieldBuilder.completeField(SchemaBuilder.java:2238)
> at
> org.apache.avro.SchemaBuilder$FieldBuilder.completeField(SchemaBuilder.java:2230)
> at
> org.apache.avro.SchemaBuilder$FieldBuilder.access$5300(SchemaBuilder.java:2148)
> at
> org.apache.avro.SchemaBuilder$GenericDefault.withDefault(SchemaBuilder.java:2545)
> {code}
> After debugging it seemed the *toJsonNode* method in SchemaBuilder is
> returning a TextNode rather than a NUMBER typed one.
> The problem can be replicated using below sample code:
> {code}
> SchemaBuilder.FieldBuilder fieldBuilder =
> SchemaBuilder.record("record").fields().name("field");
> Schema fieldSchema = Schema.create(Schema.Type.DOUBLE);
> SchemaBuilder.GenericDefault genericDefault = fieldBuilder.type(fieldSchema);
> genericDefault.withDefault(Double.NaN);
> // Exception thrown
> {code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)