avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andy Mok (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (AVRO-1861) Avro Schema parser treats Avro float type as Java Double for default values
Date Tue, 07 Jun 2016 00:05:20 GMT

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

Andy Mok updated AVRO-1861:
---------------------------
    Description: 
The following code snippet in the [Schema class|https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/Schema.java]
shows that we explicitly treat Avro {{FLOAT}} and {{DOUBLE}} as a Java {{Double}}.
{code:java}
if (defaultValue != null
    && (Type.FLOAT.equals(fieldSchema.getType())
        || Type.DOUBLE.equals(fieldSchema.getType()))
    && defaultValue.isTextual())
  defaultValue =
    new DoubleNode(Double.valueOf(defaultValue.getTextValue()));
{code}
Jackson has support for [FloatNode|https://fasterxml.github.io/jackson-databind/javadoc/2.3.0/com/fasterxml/jackson/databind/node/FloatNode.html]
so why don't we use that?

This is a problem when someone calls [Schema.Field#defaultVal|https://avro.apache.org/docs/1.8.1/api/java/org/apache/avro/Schema.Field.html#defaultVal()]
for an Avro field with Avro type {{FLOAT}} and they try to typecast the object to a Java {{float}}.


  was:
The following code snippet in the [Schema class|https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/Schema.java]
shows that we explicitly treat Avro {{FLOAT}} and {{DOUBLE}} as a Java {{Double}}.
{code:java}
if (defaultValue != null
    && (Type.FLOAT.equals(fieldSchema.getType())
        || Type.DOUBLE.equals(fieldSchema.getType()))
    && defaultValue.isTextual())
  defaultValue =
    new DoubleNode(Double.valueOf(defaultValue.getTextValue()));
{code}

This is a problem when someone calls [Schema.Field#defaultVal|https://avro.apache.org/docs/1.8.1/api/java/org/apache/avro/Schema.Field.html#defaultVal()]
for an Avro field with Avro type {{FLOAT}} and they try to typecast the object to a Java {{float}}.



> Avro Schema parser treats Avro float type as Java Double for default values
> ---------------------------------------------------------------------------
>
>                 Key: AVRO-1861
>                 URL: https://issues.apache.org/jira/browse/AVRO-1861
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.8.1
>            Reporter: Andy Mok
>
> The following code snippet in the [Schema class|https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/Schema.java]
shows that we explicitly treat Avro {{FLOAT}} and {{DOUBLE}} as a Java {{Double}}.
> {code:java}
> if (defaultValue != null
>     && (Type.FLOAT.equals(fieldSchema.getType())
>         || Type.DOUBLE.equals(fieldSchema.getType()))
>     && defaultValue.isTextual())
>   defaultValue =
>     new DoubleNode(Double.valueOf(defaultValue.getTextValue()));
> {code}
> Jackson has support for [FloatNode|https://fasterxml.github.io/jackson-databind/javadoc/2.3.0/com/fasterxml/jackson/databind/node/FloatNode.html]
so why don't we use that?
> This is a problem when someone calls [Schema.Field#defaultVal|https://avro.apache.org/docs/1.8.1/api/java/org/apache/avro/Schema.Field.html#defaultVal()]
for an Avro field with Avro type {{FLOAT}} and they try to typecast the object to a Java {{float}}.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message