[
https://issues.apache.org/jira/browse/AVRO-4108?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Sarthak Singh updated AVRO-4108:
--------------------------------
Summary: DoubleArray converts double to float on array add (was:
`DoubleAray` converts double to float on array add)
> DoubleArray converts double to float on array add
> -------------------------------------------------
>
> Key: AVRO-4108
> URL: https://issues.apache.org/jira/browse/AVRO-4108
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.12.0
> Reporter: Sarthak Singh
> Priority: Minor
>
> Consider a field within an avro schema
>
> {code:avro}
> {
> "name": "SomeDoubleArray",
> "type": {
> "type": "array",
> "items": "double"
> }
> },
> {code}
> Consider a record which fits that field
> {code:java}
> "SomeDoubleArray": [0.9, 0.8],
> {code}
> When deserializing a this record with the schema mentioned above, we get back
>
> ```
> "SomeDoubleArray": [0.8999999761581421, 0.800000011920929],
> ```
>
> The reason for this is:
> [https://github.com/apache/avro/blob/dd01f97869e374d6427bec999afa089f760791ab/lang/java/avro/src/main/java/org/apache/avro/generic/PrimitivesArrays.java#L549-L554]
>
> ```
> @Override
> public void add(int location, Double o) {
> if (o == null) {
> return;
> }
> this.add(location, o.floatValue());
> }
> ```
>
>
> When adding a double, it gets its float value and copies that to the array.
> For doubles values which cannot be represented as floats(.9 for example) we
> will see precision loss.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)