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. (opensearch-project#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 <navneev@amazon.com>
  • Loading branch information
navneet1v authored and austintlee committed Apr 28, 2023
1 parent 9608c18 commit 284c101
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 284c101

Please sign in to comment.