You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Ryan Skraba (Jira)" <ji...@apache.org> on 2020/07/02 12:21:00 UTC

[jira] [Commented] (AVRO-2858) SchemaBuilder.GenericDefault withDefault method does not handle Double.NaN correctly

    [ https://issues.apache.org/jira/browse/AVRO-2858?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17150227#comment-17150227 ] 

Ryan Skraba commented on AVRO-2858:
-----------------------------------

Very good point, thanks for the research!  It looks like the intention has always been to allow double / float values to have Infinity/-Infinity/NaN representations.  (AVRO-972 added the Java unit tests above).

> 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
>         Attachments: AVRO-2858.patch
>
>
> 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)