Skip to content

Commit

Permalink
[opensearch-project#7101] Fixing the GeoTileIT#testMultivaluedGeoPoin…
Browse files Browse the repository at this point in the history
…tsAggregation test case.

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 committed Apr 17, 2023
1 parent 632eb44 commit 2a8bffa
Show file tree
Hide file tree
Showing 2 changed files with 11 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,12 @@ protected double getRadiusOfBoundingBox() {
return 5.0;
}

protected GeoPoint toStoragePrecision(final GeoPoint geoPoint) {
// lat, long
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 2a8bffa

Please sign in to comment.