Adrien Sanchez created AVRO-4125:
------------------------------------

             Summary: Cast issue when adding Double to DoubleArray in 1.12.0
                 Key: AVRO-4125
                 URL: https://issues.apache.org/jira/browse/AVRO-4125
             Project: Apache Avro
          Issue Type: Bug
          Components: java
            Reporter: Adrien Sanchez
         Attachments: image-2025-03-21-11-43-13-178.png

Hi,

I recently upgraded to Avro 1.12.0, and I have an issue with Double objects 
when adding them to an array.

I have an Avro schema in which I have a field that represents geospatial 
coordinates :
{code:java}
{
  "name": "coordinates",
  "type": [
    "null",
    {
      "type": "array",
      "items": {
        "type": "array",
        "items": {
          "type": "array",
          "items": "double"
        }
      }
    }
  ],
  "default": null
}{code}
This was when handled in Avro 1.11.4. However, when migrating to Avro 1.12.0, 
the double items in my array came with some unexpected extra digits.

Digging into the problem, it looks like the array is handled in 1.12.0 as 
*DoubleArray* from the *PrimitivesArrays* class.
 
In this class, the add method is implemented this way :

{code:java}
public void add(int location, Double o) {
    if (o != null) {
        this.add(location, (double)o.floatValue());
    }
}
{code}

The cast to double primitive type from the float value comes with modifying the 
precision.
 
Here is an example of how the precision is modified :

!image-2025-03-21-11-43-13-178.png!

Here, I expect to add "2.64" in my array, but "2.640000104904175" is actually 
added in the end.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to