Parcourir la source

Fix test testGeoShapeBounds (#72878)

computing hashes for points is consistent between geo_shape and geo_point
Ignacio Vera il y a 4 ans
Parent
commit
310342fc2e

+ 4 - 1
x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/AbstractGeoHashGridTiler.java

@@ -37,10 +37,13 @@ abstract class AbstractGeoHashGridTiler extends GeoGridTiler {
         GeoShapeValues.BoundingBox bounds = geoValue.boundingBox();
         assert bounds.minX() <= bounds.maxX();
 
+        // When the shape represents a point, we compute the hash directly as we do it for GeoPoint
+        if (bounds.minX() == bounds.maxX() && bounds.minY() == bounds.maxY()) {
+            return setValue(values, geoValue, bounds);
+        }
         // TODO: optimize for when a  shape fits in a single tile an
         //  for when brute-force is expected to be faster than rasterization, which
         //  is when the number of tiles expected is less than the precision
-
         return setValuesByRasterization("", values, 0, geoValue);
     }
 

+ 8 - 0
x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoHashTilerTests.java

@@ -83,6 +83,14 @@ public class GeoHashTilerTests extends GeoGridTilerTestCase {
         if (precision == 0) {
             return 1;
         }
+        GeoShapeValues.BoundingBox bounds = geoValue.boundingBox();
+        if (bounds.minX() == bounds.maxX() && bounds.minY() == bounds.maxY()) {
+            String hash = Geohash.stringEncode(bounds.minX(), bounds.minY(), precision);
+            if (hashIntersectsBounds(hash, bbox) && geoValue.relate(Geohash.toBoundingBox(hash)) != GeoRelation.QUERY_DISJOINT) {
+                return 1;
+            }
+            return 0;
+        }
        return computeBuckets("", bbox, geoValue, precision);
     }
 

+ 0 - 7
x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoShapeGeoHashGridAggregatorTests.java

@@ -17,8 +17,6 @@ import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridAggregati
 import org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGridBucket;
 import org.elasticsearch.xpack.spatial.util.GeoTestUtils;
 
-import java.io.IOException;
-
 import static org.elasticsearch.geometry.utils.Geohash.stringEncode;
 
 public class GeoShapeGeoHashGridAggregatorTests extends GeoShapeGeoGridTestCase<InternalGeoHashGridBucket> {
@@ -52,9 +50,4 @@ public class GeoShapeGeoHashGridAggregatorTests extends GeoShapeGeoGridTestCase<
     protected GeoGridAggregationBuilder createBuilder(String name) {
         return new GeoHashGridAggregationBuilder(name);
     }
-
-    @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/72872")
-    public void testGeoShapeBounds() throws IOException {
-        super.testGeoShapeBounds();
-    }
 }