Skip to content

Commit b22de8f

Browse files
committed
Added Integration tests for geotile and geohash aggregations on geoshapes
Signed-off-by: Navneet Verma <navneev@amazon.com>
1 parent 3a9fdf1 commit b22de8f

File tree

8 files changed

+540
-118
lines changed

8 files changed

+540
-118
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
9494
### Added
9595
- Prevent deletion of snapshots that are backing searchable snapshot indexes ([#5069](https://github.com/opensearch-project/OpenSearch/pull/5069))
9696
- Add max_shard_size parameter for shrink API ([#5229](https://github.com/opensearch-project/OpenSearch/pull/5229))
97+
- Add GeoTile and GeoHash Grid aggregations on GeoShapes. ([]())
9798

9899
### Dependencies
99100
- Bumps `bcpg-fips` from 1.0.5.1 to 1.0.7.1

modules/geo/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ apply plugin: 'opensearch.yaml-rest-test'
3131
apply plugin: 'opensearch.internal-cluster-test'
3232

3333
opensearchplugin {
34-
description 'Plugin for geospatial features in OpenSearch. Registering the geo_shape and aggregations GeoBounds on Geo_Shape and Geo_Point'
34+
description 'Plugin for geospatial features in OpenSearch. Registering the geo_shape and aggregations on GeoShape and GeoPoint'
3535
classname 'org.opensearch.geo.GeoModulePlugin'
3636
}
3737

modules/geo/src/internalClusterTest/java/org/opensearch/geo/GeoModulePluginIntegTestCase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
package org.opensearch.geo;
1010

11+
import org.opensearch.geometry.utils.StandardValidator;
12+
import org.opensearch.geometry.utils.WellKnownText;
1113
import org.opensearch.index.mapper.GeoShapeFieldMapper;
1214
import org.opensearch.plugins.Plugin;
1315
import org.opensearch.test.OpenSearchIntegTestCase;
@@ -24,6 +26,8 @@ public abstract class GeoModulePluginIntegTestCase extends OpenSearchIntegTestCa
2426

2527
protected static final double GEOHASH_TOLERANCE = 1E-5D;
2628

29+
protected static final WellKnownText WKT = new WellKnownText(true, new StandardValidator(true));
30+
2731
/**
2832
* Returns a collection of plugins that should be loaded on each node for doing the integration tests. As this
2933
* geo plugin is not getting packaged in a zip, we need to load it before the tests run.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.geo.search.aggregations.bucket;
10+
11+
import org.opensearch.Version;
12+
import org.opensearch.action.index.IndexRequestBuilder;
13+
import org.opensearch.common.xcontent.XContentBuilder;
14+
import org.opensearch.geo.GeoModulePluginIntegTestCase;
15+
import org.opensearch.geometry.Geometry;
16+
import org.opensearch.geometry.Rectangle;
17+
import org.opensearch.test.VersionUtils;
18+
19+
import java.util.List;
20+
21+
import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
22+
23+
/**
24+
* This is the base class for all the Bucket Aggregation related integration tests. Use this class to add common
25+
* methods which can be used across different bucket aggregations. If there is any common code that can be used
26+
* across other integration test too then this is not the class. Use {@link GeoModulePluginIntegTestCase}
27+
*/
28+
public abstract class AbstractBucketAggregationIntegTest extends GeoModulePluginIntegTestCase {
29+
30+
protected static final int MAX_PRECISION_FOR_GEO_SHAPES_AGG_TESTING = 4;
31+
32+
protected static final int NUM_DOCS = 100;
33+
34+
protected static final String GEO_SHAPE_INDEX_NAME = "geoshape_index";
35+
36+
// We don't want to generate this BB at random as it may lead to generation of very large or very small BB.
37+
// Hence, we are making the parameters of this BB static for simplicity.
38+
protected static final Rectangle BOUNDING_RECTANGLE_FOR_GEO_SHAPES_AGG = new Rectangle(-4.1, 20.9, 21.9, -3.1);
39+
40+
protected static final String AGG_NAME = "geohashgrid";
41+
42+
protected static final String GEO_SHAPE_FIELD_NAME = "location_geo_shape";
43+
44+
protected static final String GEO_POINT_FIELD_NAME = "location";
45+
46+
protected static final String KEYWORD_FIELD_NAME = "city";
47+
48+
protected final Version version = VersionUtils.randomIndexCompatibleVersion(random());
49+
50+
@Override
51+
protected boolean forbidPrivateIndexSettings() {
52+
return false;
53+
}
54+
55+
protected IndexRequestBuilder indexGeoShape(final String index, final Geometry geometry) throws Exception {
56+
XContentBuilder source = jsonBuilder().startObject();
57+
source = source.field(GEO_SHAPE_FIELD_NAME, WKT.toWKT(geometry));
58+
source = source.endObject();
59+
return client().prepareIndex(index).setSource(source);
60+
}
61+
62+
protected IndexRequestBuilder indexCity(final String index, final String name, final List<String> latLon) throws Exception {
63+
XContentBuilder source = jsonBuilder().startObject().field(KEYWORD_FIELD_NAME, name);
64+
if (latLon != null) {
65+
source = source.field(GEO_POINT_FIELD_NAME, latLon);
66+
}
67+
source = source.endObject();
68+
return client().prepareIndex(index).setSource(source);
69+
}
70+
71+
protected IndexRequestBuilder indexCity(final String index, final String name, final String latLon) throws Exception {
72+
return indexCity(index, name, List.of(latLon));
73+
}
74+
75+
}

0 commit comments

Comments
 (0)