Skip to content

Commit 4751f3b

Browse files
authored
Refactor the src and test of GeoBoundsAggregation on GeoPoint from server folder to geo module.
Refactors the GeoBoundsAggregation for geo_point types from the core server to the geo module. Signed-off-by: Navneet Verma <navneev@amazon.com>
1 parent a120dd2 commit 4751f3b

File tree

28 files changed

+799
-228
lines changed

28 files changed

+799
-228
lines changed

client/rest-high-level/src/main/java/org/opensearch/client/RestHighLevelClient.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@
157157
import org.opensearch.search.aggregations.metrics.AvgAggregationBuilder;
158158
import org.opensearch.search.aggregations.metrics.CardinalityAggregationBuilder;
159159
import org.opensearch.search.aggregations.metrics.ExtendedStatsAggregationBuilder;
160-
import org.opensearch.search.aggregations.metrics.GeoBoundsAggregationBuilder;
161160
import org.opensearch.search.aggregations.metrics.GeoCentroidAggregationBuilder;
162161
import org.opensearch.search.aggregations.metrics.InternalHDRPercentileRanks;
163162
import org.opensearch.search.aggregations.metrics.InternalHDRPercentiles;
@@ -169,7 +168,6 @@
169168
import org.opensearch.search.aggregations.metrics.ParsedAvg;
170169
import org.opensearch.search.aggregations.metrics.ParsedCardinality;
171170
import org.opensearch.search.aggregations.metrics.ParsedExtendedStats;
172-
import org.opensearch.search.aggregations.metrics.ParsedGeoBounds;
173171
import org.opensearch.search.aggregations.metrics.ParsedGeoCentroid;
174172
import org.opensearch.search.aggregations.metrics.ParsedHDRPercentileRanks;
175173
import org.opensearch.search.aggregations.metrics.ParsedHDRPercentiles;
@@ -2116,7 +2114,6 @@ static List<NamedXContentRegistry.Entry> getDefaultNamedXContents() {
21162114
map.put(StatsBucketPipelineAggregationBuilder.NAME, (p, c) -> ParsedStatsBucket.fromXContent(p, (String) c));
21172115
map.put(ExtendedStatsAggregationBuilder.NAME, (p, c) -> ParsedExtendedStats.fromXContent(p, (String) c));
21182116
map.put(ExtendedStatsBucketPipelineAggregationBuilder.NAME, (p, c) -> ParsedExtendedStatsBucket.fromXContent(p, (String) c));
2119-
map.put(GeoBoundsAggregationBuilder.NAME, (p, c) -> ParsedGeoBounds.fromXContent(p, (String) c));
21202117
map.put(GeoCentroidAggregationBuilder.NAME, (p, c) -> ParsedGeoCentroid.fromXContent(p, (String) c));
21212118
map.put(HistogramAggregationBuilder.NAME, (p, c) -> ParsedHistogram.fromXContent(p, (String) c));
21222119
map.put(DateHistogramAggregationBuilder.NAME, (p, c) -> ParsedDateHistogram.fromXContent(p, (String) c));

modules/geo/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
* under the License.
2929
*/
3030
apply plugin: 'opensearch.yaml-rest-test'
31+
apply plugin: 'opensearch.internal-cluster-test'
3132

3233
opensearchplugin {
33-
description 'Placeholder plugin for geospatial features in OpenSearch. only registers geo_shape field mapper for now'
34+
description 'Plugin for geospatial features in OpenSearch. Registering the geo_shape and aggregations GeoBounds on Geo_Shape and Geo_Point'
3435
classname 'org.opensearch.geo.GeoModulePlugin'
3536
}
3637

@@ -42,4 +43,3 @@ restResources {
4243
artifacts {
4344
restTests(project.file('src/yamlRestTest/resources/rest-api-spec/test'))
4445
}
45-
test.enabled = false
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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;
10+
11+
import org.opensearch.index.mapper.GeoShapeFieldMapper;
12+
import org.opensearch.plugins.Plugin;
13+
import org.opensearch.test.OpenSearchIntegTestCase;
14+
import org.opensearch.test.TestGeoShapeFieldMapperPlugin;
15+
16+
import java.util.Collection;
17+
import java.util.Collections;
18+
19+
/**
20+
* This is the base class for all the Geo related integration tests. Use this class to add the features and settings
21+
* for the test cluster on which integration tests are running.
22+
*/
23+
public abstract class GeoModulePluginIntegTestCase extends OpenSearchIntegTestCase {
24+
/**
25+
* Returns a collection of plugins that should be loaded on each node for doing the integration tests. As this
26+
* geo plugin is not getting packaged in a zip, we need to load it before the tests run.
27+
*
28+
* @return List of {@link Plugin}
29+
*/
30+
@Override
31+
protected Collection<Class<? extends Plugin>> nodePlugins() {
32+
return Collections.singletonList(GeoModulePlugin.class);
33+
}
34+
35+
/**
36+
* This was added as a backdoor to Mock the implementation of {@link GeoShapeFieldMapper} which was coming from
37+
* {@link GeoModulePlugin}. Mock implementation is {@link TestGeoShapeFieldMapperPlugin}. Now we are using the
38+
* {@link GeoModulePlugin} in our integration tests we need to override this functionality to avoid multiple mapper
39+
* error.
40+
*
41+
* @return boolean
42+
*/
43+
@Override
44+
protected boolean addMockGeoShapeFieldMapper() {
45+
return false;
46+
}
47+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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;
10+
11+
import org.opensearch.action.search.SearchResponse;
12+
import org.opensearch.geo.GeoModulePluginIntegTestCase;
13+
import org.opensearch.geo.search.aggregations.metrics.GeoBounds;
14+
import org.opensearch.geo.tests.common.AggregationBuilders;
15+
import org.opensearch.test.OpenSearchIntegTestCase;
16+
17+
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
18+
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse;
19+
import static org.hamcrest.Matchers.closeTo;
20+
21+
@OpenSearchIntegTestCase.SuiteScopeTestCase
22+
public class MissingValueIT extends GeoModulePluginIntegTestCase {
23+
24+
@Override
25+
protected void setupSuiteScopeCluster() throws Exception {
26+
assertAcked(prepareCreate("idx").setMapping("date", "type=date", "location", "type=geo_point", "str", "type=keyword").get());
27+
indexRandom(
28+
true,
29+
client().prepareIndex("idx").setId("1").setSource(),
30+
client().prepareIndex("idx")
31+
.setId("2")
32+
.setSource("str", "foo", "long", 3L, "double", 5.5, "date", "2015-05-07", "location", "1,2")
33+
);
34+
}
35+
36+
public void testUnmappedGeoBounds() {
37+
SearchResponse response = client().prepareSearch("idx")
38+
.addAggregation(AggregationBuilders.geoBounds("bounds").field("non_existing_field").missing("2,1"))
39+
.get();
40+
assertSearchResponse(response);
41+
GeoBounds bounds = response.getAggregations().get("bounds");
42+
assertThat(bounds.bottomRight().lat(), closeTo(2.0, 1E-5));
43+
assertThat(bounds.bottomRight().lon(), closeTo(1.0, 1E-5));
44+
assertThat(bounds.topLeft().lat(), closeTo(2.0, 1E-5));
45+
assertThat(bounds.topLeft().lon(), closeTo(1.0, 1E-5));
46+
}
47+
48+
public void testGeoBounds() {
49+
SearchResponse response = client().prepareSearch("idx")
50+
.addAggregation(AggregationBuilders.geoBounds("bounds").field("location").missing("2,1"))
51+
.get();
52+
assertSearchResponse(response);
53+
GeoBounds bounds = response.getAggregations().get("bounds");
54+
assertThat(bounds.bottomRight().lat(), closeTo(1.0, 1E-5));
55+
assertThat(bounds.bottomRight().lon(), closeTo(2.0, 1E-5));
56+
assertThat(bounds.topLeft().lat(), closeTo(2.0, 1E-5));
57+
assertThat(bounds.topLeft().lon(), closeTo(1.0, 1E-5));
58+
}
59+
}

0 commit comments

Comments
 (0)