You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Thiruvalluvan M. G. (JIRA)" <ji...@apache.org> on 2018/12/30 04:37:00 UTC

[jira] [Updated] (AVRO-2260) IDL Json Parsing is lossy, and it could be made more accurate.

     [ https://issues.apache.org/jira/browse/AVRO-2260?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thiruvalluvan M. G. updated AVRO-2260:
--------------------------------------
    Component/s: java

> IDL Json Parsing is lossy, and it could be made more accurate.
> --------------------------------------------------------------
>
>                 Key: AVRO-2260
>                 URL: https://issues.apache.org/jira/browse/AVRO-2260
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>            Reporter: Zoltan Farkas
>            Priority: Minor
>
> Currently all integers are handled as Long, and all floating point as Double, having basically the following issues:
> 1) cannot handle numbers larger that MAXLONG.
> 2) introducing unnecessary precision 
> {code}
> JsonNode Json() :
> { String s; Token t; JsonNode n; }
> { 
> ( s = JsonString() { n = new TextNode(s); }
> | (t=<INTEGER_LITERAL> { n = new LongNode(Long.parseLong(t.image)); })
> | (t=<FLOATING_POINT_LITERAL> {n=new DoubleNode(Double.parseDouble(t.image));})
> | n=JsonObject()
> | n=JsonArray()
> | ( "true" { n = BooleanNode.TRUE; } )
> | ( "false" { n = BooleanNode.FALSE; } )
> | ( "null" { n = NullNode.instance; } )
>  )
>   { return n; }
> }
> {code}
> This should be improved to:
> {code}
> JsonNode Json() :
> { String s; Token t; JsonNode n; }
> { 
> ( s = JsonString() { n = new TextNode(s); }
> | (t=<INTEGER_LITERAL> {
>            try {
>              n = new IntNode(Integer.parseInt(t.image));
>            } catch(NumberFormatException  e) {
>              try {
>                 n = new LongNode(Long.parseLong(t.image));
>              } catch(NumberFormatException  ex2) {
>                 n = new BigIntegerNode(new java.math.BigInteger(t.image));
>              }
>            }
>  })
> | (t=<FLOATING_POINT_LITERAL> {n=new DecimalNode(new java.math.BigDecimal(t.image));})
> | n=JsonObject()
> | n=JsonArray()
> | ( "true" { n = BooleanNode.TRUE; } )
> | ( "false" { n = BooleanNode.FALSE; } )
> | ( "null" { n = NullNode.instance; } )
>  )
>   { return n; }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)