Skip to content

Commit

Permalink
Fix precision issue in CI for cartesian centroids (#104707)
Browse files Browse the repository at this point in the history
Even with Kahan summation, there is a tiny precisoin loss. We already fixed this before for GeoPoint by using the encode/decode to doc-values quantization in the final display results, and for CartesianPoint we fix by casting the coordinates to float for both the expected and actual results.
  • Loading branch information
craigtaverner authored Jan 24, 2024
1 parent 9d3207c commit 7ef80f2
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,30 @@ private static Object valueMapper(CsvTestUtils.Type type, Object value) {
if (value == null) {
return "null";
}
if (type == CsvTestUtils.Type.GEO_POINT) {
// GeoPoint tests are failing in clustered integration tests because of tiny precision differences at very small scales
if (type == CsvTestUtils.Type.GEO_POINT || type == CsvTestUtils.Type.CARTESIAN_POINT) {
// Point tests are failing in clustered integration tests because of tiny precision differences at very small scales
if (value instanceof GeoPoint point) {
return normalizedGeoPoint(point.getX(), point.getY());
}
if (value instanceof String wkt) {
try {
Geometry geometry = WellKnownText.fromWKT(GeometryValidator.NOOP, false, wkt);
if (geometry instanceof Point point) {
return normalizedGeoPoint(point.getX(), point.getY());
return normalizedPoint(type, point.getX(), point.getY());
}
} catch (Throwable ignored) {}
}
}
return value.toString();
}

private static String normalizedPoint(CsvTestUtils.Type type, double x, double y) {
if (type == CsvTestUtils.Type.GEO_POINT) {
return normalizedGeoPoint(x, y);
}
return String.format(Locale.ROOT, "POINT (%f %f)", (float) x, (float) y);
}

private static String normalizedGeoPoint(double x, double y) {
x = decodeLongitude(encodeLongitude(x));
y = decodeLatitude(encodeLatitude(y));
Expand Down

0 comments on commit 7ef80f2

Please sign in to comment.