From 77a1f0e1f42ec6f0077ef4c3e18bc4c75befd903 Mon Sep 17 00:00:00 2001 From: Navneet Verma Date: Wed, 8 Feb 2023 12:07:12 -0800 Subject: [PATCH 1/2] [#6187, #6222] Fixing the GeoShapes GeoHash and GeoTile Aggregations Integration tests to make them more robust. Signed-off-by: Navneet Verma --- ...AbstractGeoBucketAggregationIntegTest.java | 13 +++------- .../aggregations/bucket/GeoHashGridIT.java | 9 +++---- .../aggregations/bucket/GeoTileGridIT.java | 10 ++++---- .../geogrid/cells/GeoShapeCellValues.java | 25 ++++++------------- 4 files changed, 20 insertions(+), 37 deletions(-) diff --git a/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/AbstractGeoBucketAggregationIntegTest.java b/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/AbstractGeoBucketAggregationIntegTest.java index 299ba0640ef8b..229a05ab501b1 100644 --- a/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/AbstractGeoBucketAggregationIntegTest.java +++ b/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/AbstractGeoBucketAggregationIntegTest.java @@ -98,7 +98,7 @@ protected void prepareGeoShapeIndexForAggregations(final Random random) throws E } i++; - final Set values = generateBucketsForGeometry(geometry, geometryDocValue, isShapeIntersectingBB); + final Set values = generateBucketsForGeometry(geometry, geometryDocValue); geoshapes.add(indexGeoShape(GEO_SHAPE_INDEX_NAME, geometry)); for (final String hash : values) { expectedDocsCountForGeoShapes.put(hash, expectedDocsCountForGeoShapes.getOrDefault(hash, 0) + 1); @@ -112,16 +112,11 @@ protected void prepareGeoShapeIndexForAggregations(final Random random) throws E * Returns a set of buckets for the shape at different precision level. Override this method for different bucket * aggregations. * - * @param geometry {@link Geometry} - * @param geoShapeDocValue {@link GeoShapeDocValue} - * @param intersectingWithBB boolean + * @param geometry {@link Geometry} + * @param geoShapeDocValue {@link GeoShapeDocValue} * @return A {@link Set} of {@link String} which represents the buckets. */ - protected abstract Set generateBucketsForGeometry( - final Geometry geometry, - final GeoShapeDocValue geoShapeDocValue, - final boolean intersectingWithBB - ); + protected abstract Set generateBucketsForGeometry(final Geometry geometry, final GeoShapeDocValue geoShapeDocValue); /** * Prepares a GeoPoint index for testing the GeoPoint bucket aggregations. Different bucket aggregations can use diff --git a/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoHashGridIT.java b/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoHashGridIT.java index e24f69ea247f2..70b3015189818 100644 --- a/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoHashGridIT.java +++ b/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoHashGridIT.java @@ -268,18 +268,15 @@ public void testShardSizeIsZero() { } @Override - protected Set generateBucketsForGeometry( - final Geometry geometry, - final GeoShapeDocValue geometryDocValue, - boolean intersectingWithBB - ) { + protected Set generateBucketsForGeometry(final Geometry geometry, final GeoShapeDocValue geometryDocValue) { final GeoPoint topLeft = new GeoPoint(); final GeoPoint bottomRight = new GeoPoint(); assert geometry != null; GeoBoundsHelper.updateBoundsForGeometry(geometry, topLeft, bottomRight); final Set geoHashes = new HashSet<>(); for (int precision = MAX_PRECISION_FOR_GEO_SHAPES_AGG_TESTING; precision > 0; precision--) { - if (precision > MIN_PRECISION_WITHOUT_BB_AGGS && intersectingWithBB == false) { + if (precision > MIN_PRECISION_WITHOUT_BB_AGGS + && geometryDocValue.isIntersectingRectangle(boundingRectangleForGeoShapesAgg) == false) { continue; } final GeoPoint topRight = new GeoPoint(topLeft.getLat(), bottomRight.getLon()); diff --git a/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoTileGridIT.java b/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoTileGridIT.java index 8a8f8572066e9..575aa8470bf58 100644 --- a/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoTileGridIT.java +++ b/modules/geo/src/internalClusterTest/java/org/opensearch/geo/search/aggregations/bucket/GeoTileGridIT.java @@ -134,20 +134,20 @@ public void testMultivaluedGeoPointsAggregation() throws Exception { * Returns a set of buckets for the shape at different precision level. Override this method for different bucket * aggregations. * - * @param geometry {@link Geometry} - * @param geoShapeDocValue {@link GeoShapeDocValue} - * @param intersectingWithBB + * @param geometry {@link Geometry} + * @param geoShapeDocValue {@link GeoShapeDocValue} * @return A {@link Set} of {@link String} which represents the buckets. */ @Override - protected Set generateBucketsForGeometry(Geometry geometry, GeoShapeDocValue geoShapeDocValue, boolean intersectingWithBB) { + protected Set generateBucketsForGeometry(Geometry geometry, GeoShapeDocValue geoShapeDocValue) { final GeoPoint topLeft = new GeoPoint(); final GeoPoint bottomRight = new GeoPoint(); assert geometry != null; GeoBoundsHelper.updateBoundsForGeometry(geometry, topLeft, bottomRight); final Set geoTiles = new HashSet<>(); for (int precision = MAX_PRECISION_FOR_GEO_SHAPES_AGG_TESTING; precision > 0; precision--) { - if (precision > MIN_PRECISION_WITHOUT_BB_AGGS && intersectingWithBB == false) { + if (precision > MIN_PRECISION_WITHOUT_BB_AGGS + && geoShapeDocValue.isIntersectingRectangle(boundingRectangleForGeoShapesAgg) == false) { continue; } geoTiles.addAll( diff --git a/modules/geo/src/main/java/org/opensearch/geo/search/aggregations/bucket/geogrid/cells/GeoShapeCellValues.java b/modules/geo/src/main/java/org/opensearch/geo/search/aggregations/bucket/geogrid/cells/GeoShapeCellValues.java index 4911818cd448f..123a98fab3713 100644 --- a/modules/geo/src/main/java/org/opensearch/geo/search/aggregations/bucket/geogrid/cells/GeoShapeCellValues.java +++ b/modules/geo/src/main/java/org/opensearch/geo/search/aggregations/bucket/geogrid/cells/GeoShapeCellValues.java @@ -10,6 +10,7 @@ import org.opensearch.common.geo.GeoBoundingBox; import org.opensearch.common.geo.GeoShapeDocValue; +import org.opensearch.geometry.Rectangle; import org.opensearch.index.fielddata.AbstractSortingNumericDocValues; import org.opensearch.index.fielddata.GeoShapeValue; @@ -57,8 +58,7 @@ public boolean advanceExact(int docId) throws IOException { * @opensearch.internal */ static class BoundedCellValues extends GeoShapeCellValues { - - private final GeoBoundingBox geoBoundingBox; + private final Rectangle geoBoundingBox; public BoundedCellValues( final GeoShapeValue geoShapeValue, @@ -67,7 +67,7 @@ public BoundedCellValues( final GeoBoundingBox boundingBox ) { super(geoShapeValue, precision, encoder); - this.geoBoundingBox = boundingBox; + this.geoBoundingBox = new Rectangle(boundingBox.left(), boundingBox.right(), boundingBox.top(), boundingBox.bottom()); } /** @@ -78,7 +78,7 @@ public BoundedCellValues( */ @Override void relateShape(final GeoShapeDocValue geoShapeDocValue) { - if (intersect(geoShapeDocValue.getBoundingRectangle())) { + if (geoShapeDocValue.isIntersectingRectangle(geoBoundingBox)) { // now we know the shape is in the bounding rectangle, we need add them in longValues // generate all grid that this shape intersects final List encodedValues = encoder.encode(geoShapeDocValue, precision); @@ -86,22 +86,13 @@ void relateShape(final GeoShapeDocValue geoShapeDocValue) { for (int i = 0; i < encodedValues.size(); i++) { values[i] = encodedValues.get(i); } + } else { + // As the shape is not intersecting with GeoBounding box, we need to reset the GeoShapeCellValues + // calling this function resets the CellValues for the current shape. + resize(0); } } - /** - * Validate that shape is intersecting the bounding box provided as input. - * - * @param rectangle {@link GeoShapeDocValue.BoundingRectangle} - * @return true or false - */ - private boolean intersect(final GeoShapeDocValue.BoundingRectangle rectangle) { - return geoBoundingBox.pointInBounds(rectangle.getMaxLongitude(), rectangle.getMaxLatitude()) - || geoBoundingBox.pointInBounds(rectangle.getMaxLongitude(), rectangle.getMinLatitude()) - || geoBoundingBox.pointInBounds(rectangle.getMinLongitude(), rectangle.getMaxLatitude()) - || geoBoundingBox.pointInBounds(rectangle.getMinLongitude(), rectangle.getMinLatitude()); - } - } /** From b186c50b8f3e5fcf371516f1eec0fa05fc2a1c58 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 8 Feb 2023 20:14:51 +0000 Subject: [PATCH 2/2] Bump spock-core from 2.3-groovy-3.0 to 2.3-groovy-4.0 in /buildSrc Bumps spock-core from 2.3-groovy-3.0 to 2.3-groovy-4.0. --- updated-dependencies: - dependency-name: org.spockframework:spock-core dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- buildSrc/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index ad734a403861a..51e4c774ad3ea 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -127,7 +127,7 @@ dependencies { testFixturesApi gradleTestKit() testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone:2.35.0' testImplementation "org.mockito:mockito-core:${props.getProperty('mockito')}" - integTestImplementation('org.spockframework:spock-core:2.3-groovy-3.0') { + integTestImplementation('org.spockframework:spock-core:2.3-groovy-4.0') { exclude module: "groovy" } }