Skip to content

Commit

Permalink
[#7101] Fixing the GeoTileIT#testMultivaluedGeoPointsAggregation test…
Browse files Browse the repository at this point in the history
… case. (#7166)

The issue was happening because we encode the GeoPoint as long and error comes in the precision due to that encoding. The error was not taken care while generating the exepected tiles count for execpected output.

Signed-off-by: Navneet Verma <[email protected]>
  • Loading branch information
navneet1v authored Apr 17, 2023
1 parent 46bdf21 commit 4897582
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.carrotsearch.hppc.ObjectIntHashMap;
import com.carrotsearch.hppc.ObjectIntMap;
import org.apache.lucene.geo.GeoEncodingUtils;
import org.opensearch.Version;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.cluster.metadata.IndexMetadata;
Expand Down Expand Up @@ -254,4 +255,17 @@ protected double getRadiusOfBoundingBox() {
return 5.0;
}

/**
* Encode and Decode the {@link GeoPoint} to get a {@link GeoPoint} which has the exact precision which is being
* stored.
* @param geoPoint {@link GeoPoint}
* @return {@link GeoPoint}
*/
protected GeoPoint toStoragePrecision(final GeoPoint geoPoint) {
return new GeoPoint(
GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(geoPoint.getLat())),
GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(geoPoint.getLon()))
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ protected Set<String> generateBucketsForGeometry(final Geometry geometry, final
protected Set<String> generateBucketsForGeoPoint(final GeoPoint geoPoint) {
Set<String> buckets = new HashSet<>();
for (int precision = GEOPOINT_MAX_PRECISION; precision > 0; precision--) {
final String tile = GeoTileUtils.stringEncode(geoPoint.getLon(), geoPoint.getLat(), precision);
final GeoPoint precisedGeoPoint = this.toStoragePrecision(geoPoint);
final String tile = GeoTileUtils.stringEncode(precisedGeoPoint.getLon(), precisedGeoPoint.getLat(), precision);
buckets.add(tile);
}
return buckets;
Expand Down

0 comments on commit 4897582

Please sign in to comment.