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 <navneev@amazon.com>
  • Loading branch information
navneet1v authored and heemin32 committed Jun 27, 2023
1 parent 06dea54 commit 23e928f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

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;
import org.opensearch.common.geo.GeoPoint;
import org.opensearch.common.geo.GeoShapeDocValue;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.geo.GeoModulePluginIntegTestCase;
import org.opensearch.geo.tests.common.RandomGeoGenerator;
import org.opensearch.geo.tests.common.RandomGeoGeometryGenerator;
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 23e928f

Please sign in to comment.