Skip to content

Commit a69cb06

Browse files
committed
[opensearch-project/geospatial#212] Fixing the IT for GeoTilesAggregation.
Signed-off-by: Navneet Verma <navneev@amazon.com>
1 parent b1cf2d1 commit a69cb06

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/AbstractGeoBucketAggregationIntegTest.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public abstract class AbstractGeoBucketAggregationIntegTest extends GeoModulePlu
4242

4343
protected static final int MAX_PRECISION_FOR_GEO_SHAPES_AGG_TESTING = 4;
4444

45+
protected static final int MIN_PRECISION_WITHOUT_BB_AGGS = 2;
46+
4547
protected static final int NUM_DOCS = 100;
4648

4749
protected static final String GEO_SHAPE_INDEX_NAME = "geoshape_index";
@@ -88,14 +90,13 @@ protected void prepareGeoShapeIndexForAggregations(final Random random) throws E
8890
final Geometry geometry = RandomGeoGeometryGenerator.randomGeometry(random);
8991
final GeoShapeDocValue geometryDocValue = GeoShapeDocValue.createGeometryDocValue(geometry);
9092
// make sure that there is 1 shape is intersecting with the bounding box
91-
if (!isShapeIntersectingBB) {
92-
isShapeIntersectingBB = geometryDocValue.isIntersectingRectangle(boundingRectangleForGeoShapesAgg);
93-
if (!isShapeIntersectingBB && i == NUM_DOCS - 1) {
94-
continue;
95-
}
93+
isShapeIntersectingBB = geometryDocValue.isIntersectingRectangle(boundingRectangleForGeoShapesAgg);
94+
if (!isShapeIntersectingBB && i == NUM_DOCS - 1) {
95+
continue;
9696
}
97+
9798
i++;
98-
final Set<String> values = generateBucketsForGeometry(geometry, geometryDocValue);
99+
final Set<String> values = generateBucketsForGeometry(geometry, geometryDocValue, isShapeIntersectingBB);
99100
geoshapes.add(indexGeoShape(GEO_SHAPE_INDEX_NAME, geometry));
100101
for (final String hash : values) {
101102
expectedDocsCountForGeoShapes.put(hash, expectedDocsCountForGeoShapes.getOrDefault(hash, 0) + 1);
@@ -109,11 +110,14 @@ protected void prepareGeoShapeIndexForAggregations(final Random random) throws E
109110
* Returns a set of buckets for the shape at different precision level. Override this method for different bucket
110111
* aggregations.
111112
*
112-
* @param geometry {@link Geometry}
113-
* @param geoShapeDocValue {@link GeoShapeDocValue}
113+
* @param geometry {@link Geometry}
114+
* @param geoShapeDocValue {@link GeoShapeDocValue}
115+
* @param intersectingWithBB boolean
114116
* @return A {@link Set} of {@link String} which represents the buckets.
115117
*/
116-
protected abstract Set<String> generateBucketsForGeometry(final Geometry geometry, final GeoShapeDocValue geoShapeDocValue);
118+
protected abstract Set<String> generateBucketsForGeometry(final Geometry geometry,
119+
final GeoShapeDocValue geoShapeDocValue,
120+
final boolean intersectingWithBB);
117121

118122
/**
119123
* Prepares a GeoPoint index for testing the GeoPoint bucket aggregations. Different bucket aggregations can use

modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoHashGridIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void testGeoShapes() {
112112
GeoGridAggregationBuilder builder = AggregationBuilders.geohashGrid(AGG_NAME).field(GEO_SHAPE_FIELD_NAME).precision(precision);
113113
// This makes sure that for only higher precision we are providing the GeoBounding Box. This also ensures
114114
// that we are able to test both bounded and unbounded aggregations
115-
if (precision > 2) {
115+
if (precision > MIN_PRECISION_WITHOUT_BB_AGGS) {
116116
builder.setGeoBoundingBox(boundingBox);
117117
}
118118
final SearchResponse response = client().prepareSearch(GEO_SHAPE_INDEX_NAME).addAggregation(builder).get();
@@ -268,14 +268,14 @@ public void testShardSizeIsZero() {
268268
}
269269

270270
@Override
271-
protected Set<String> generateBucketsForGeometry(final Geometry geometry, final GeoShapeDocValue geometryDocValue) {
271+
protected Set<String> generateBucketsForGeometry(final Geometry geometry, final GeoShapeDocValue geometryDocValue, boolean intersectingWithBB) {
272272
final GeoPoint topLeft = new GeoPoint();
273273
final GeoPoint bottomRight = new GeoPoint();
274274
assert geometry != null;
275275
GeoBoundsHelper.updateBoundsForGeometry(geometry, topLeft, bottomRight);
276276
final Set<String> geoHashes = new HashSet<>();
277277
for (int precision = MAX_PRECISION_FOR_GEO_SHAPES_AGG_TESTING; precision > 0; precision--) {
278-
if (precision > 2 && !geometryDocValue.isIntersectingRectangle(boundingRectangleForGeoShapesAgg)) {
278+
if (precision > MIN_PRECISION_WITHOUT_BB_AGGS && !intersectingWithBB) {
279279
continue;
280280
}
281281
final GeoPoint topRight = new GeoPoint(topLeft.getLat(), bottomRight.getLon());

modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoTileGridIT.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void testGeoShapes() {
6060
.precision(precision);
6161
// This makes sure that for only higher precision we are providing the GeoBounding Box. This also ensures
6262
// that we are able to test both bounded and unbounded aggregations
63-
if (precision > 2) {
63+
if (precision > MIN_PRECISION_WITHOUT_BB_AGGS) {
6464
builder.setGeoBoundingBox(boundingBox);
6565
}
6666
final SearchResponse response = client().prepareSearch(GEO_SHAPE_INDEX_NAME).addAggregation(builder).get();
@@ -134,18 +134,22 @@ public void testMultivaluedGeoPointsAggregation() throws Exception {
134134
* Returns a set of buckets for the shape at different precision level. Override this method for different bucket
135135
* aggregations.
136136
*
137-
* @param geometry {@link Geometry}
138-
* @param geoShapeDocValue {@link GeoShapeDocValue}
137+
* @param geometry {@link Geometry}
138+
* @param geoShapeDocValue {@link GeoShapeDocValue}
139+
* @param intersectingWithBB
139140
* @return A {@link Set} of {@link String} which represents the buckets.
140141
*/
141142
@Override
142-
protected Set<String> generateBucketsForGeometry(Geometry geometry, GeoShapeDocValue geoShapeDocValue) {
143+
protected Set<String> generateBucketsForGeometry(Geometry geometry, GeoShapeDocValue geoShapeDocValue, boolean intersectingWithBB) {
143144
final GeoPoint topLeft = new GeoPoint();
144145
final GeoPoint bottomRight = new GeoPoint();
145146
assert geometry != null;
146147
GeoBoundsHelper.updateBoundsForGeometry(geometry, topLeft, bottomRight);
147148
final Set<String> geoTiles = new HashSet<>();
148149
for (int precision = MAX_PRECISION_FOR_GEO_SHAPES_AGG_TESTING; precision > 0; precision--) {
150+
if(precision > MIN_PRECISION_WITHOUT_BB_AGGS && !intersectingWithBB) {
151+
continue;
152+
}
149153
geoTiles.addAll(
150154
GeoTileUtils.encodeShape(geoShapeDocValue, precision).stream().map(GeoTileUtils::stringEncode).collect(Collectors.toSet())
151155
);

0 commit comments

Comments
 (0)