You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Kornel Kiełczewski (JIRA)" <ji...@apache.org> on 2017/10/25 14:00:02 UTC

[jira] [Comment Edited] (AVRO-2099) Decimal precision is ignored

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

Kornel Kiełczewski edited comment on AVRO-2099 at 10/25/17 1:59 PM:
--------------------------------------------------------------------

What I meant was that 1234560.00 should not serialize to a schema with precision=4 and scale=2, hence the precision of the schema is too small. If I understand that correctly.

Deserialization: you're right, good catch. Essentialy we have as of now serialized objects in the wild with an incompatible schema :)




was (Author: kornelkielczewski):
What I meant was that 1234560.00 should not serialize to a schema with precision=4 and scale=2

Deserialization: you're right, good catch. Essentialy we have as of now serialized objects in the wild with an incompatible schema :)



> Decimal precision is ignored
> ----------------------------
>
>                 Key: AVRO-2099
>                 URL: https://issues.apache.org/jira/browse/AVRO-2099
>             Project: Avro
>          Issue Type: Improvement
>            Reporter: Kornel Kiełczewski
>
> According to the documentation https://avro.apache.org/docs/1.8.1/spec.html#Decimal 
> {quote}
> The decimal logical type represents an arbitrary-precision signed decimal number of the form unscaled × 10-scale.
> {quote}
> Then in the schema we might have an entry like:
> {code}
> {
>   "type": "bytes",
>   "logicalType": "decimal",
>   "precision": 4,
>   "scale": 2
> }
> {code}
> However, in the java deserialization I see that the precision is ignored:
> https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/Conversions.java#L79
> {code}
>     @Override
>     public BigDecimal fromBytes(ByteBuffer value, Schema schema, LogicalType type) {
>       int scale = ((LogicalTypes.Decimal) type).getScale();
>       // always copy the bytes out because BigInteger has no offset/length ctor
>       byte[] bytes = new byte[value.remaining()];
>       value.get(bytes);
>       return new BigDecimal(new BigInteger(bytes), scale);
>     }
> {code}
> The logical type definition in the java api requires the precision to be set:
> https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java#L116
> {code}
>   /** Create a Decimal LogicalType with the given precision and scale */
>   public static Decimal decimal(int precision, int scale) {
>     return new Decimal(precision, scale);
>   }
> {code}
> Is this a feature, that we allow arbitrary precision? If so, why do we have the precision in the API and schema, if it's ignored?
> Maybe that's some java specific issue?
> Thanks for any hints.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)