Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVRO-2108: [Java] DoubleArray converts double to float on array add #3285

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Integer get(int i) {

/**
* Direct primitive int access.
*
*
* @param i : index.
* @return value at index.
*/
Expand Down Expand Up @@ -162,7 +162,7 @@ public Long get(int i) {

/**
* Direct primitive int access.
*
*
* @param i : index.
* @return value at index.
*/
Expand Down Expand Up @@ -273,7 +273,7 @@ public Boolean get(int i) {

/**
* Direct primitive int access.
*
*
* @param i : index.
* @return value at index.
*/
Expand Down Expand Up @@ -431,7 +431,7 @@ public Float get(int i) {

/**
* Direct primitive int access.
*
*
* @param i : index.
* @return value at index.
*/
Expand Down Expand Up @@ -535,7 +535,7 @@ public Double get(int i) {

/**
* Direct primitive int access.
*
*
* @param i : index.
* @return value at index.
*/
Expand All @@ -550,7 +550,7 @@ public void add(int location, Double o) {
if (o == null) {
return;
}
this.add(location, o.floatValue());
this.add(location, o.doubleValue());
}

public void add(int location, double o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,18 @@ void doubleArray() {
Assertions.assertEquals((101 - i) * 3.0d, doubleArray.get(i - 1));
}
}

@Test
martin-g marked this conversation as resolved.
Show resolved Hide resolved
void testDoubleArrayPreservesPrecisionForNonFloatRepresentableValues() {
final PrimitivesArrays.DoubleArray doubleArray = new PrimitivesArrays.DoubleArray(1,
Schema.createArray(Schema.create(Schema.Type.DOUBLE)));

// This value cannot be represented as a float
Double nonFloatDouble = .9;
Assertions.assertNotEquals(.9, nonFloatDouble.floatValue());

// Assert that the double array does not lose precision when adding
doubleArray.add(nonFloatDouble);
Assertions.assertEquals(nonFloatDouble, doubleArray.get(0));
}
}
Loading