Skip to content

Commit d8229ac

Browse files
authored
Remove legacy geo code from AggregationResultUtils (#77702)
1 parent 9275eca commit d8229ac

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/AggregationResultUtils.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
import org.elasticsearch.ElasticsearchException;
1111
import org.elasticsearch.common.Numbers;
1212
import org.elasticsearch.common.geo.GeoPoint;
13-
import org.elasticsearch.common.geo.builders.LineStringBuilder;
14-
import org.elasticsearch.common.geo.builders.PointBuilder;
15-
import org.elasticsearch.common.geo.builders.PolygonBuilder;
16-
import org.elasticsearch.common.geo.parsers.ShapeParser;
13+
1714
import org.elasticsearch.geometry.Rectangle;
1815
import org.elasticsearch.index.mapper.DateFieldMapper;
1916
import org.elasticsearch.search.aggregations.Aggregation;
@@ -82,6 +79,12 @@ public final class AggregationResultUtils {
8279
BUCKET_KEY_EXTRACTOR_MAP = Collections.unmodifiableMap(tempMap);
8380
}
8481

82+
private static final String FIELD_TYPE = "type";
83+
private static final String FIELD_COORDINATES = "coordinates";
84+
private static final String POINT = "point";
85+
private static final String LINESTRING = "linestring";
86+
private static final String POLYGON = "polygon";
87+
8588
/**
8689
* Extracts aggregation results from a composite aggregation and puts it into a map.
8790
*
@@ -413,29 +416,29 @@ public Object value(Aggregation agg, Map<String, String> fieldTypeMap, String lo
413416
final Map<String, Object> geoShape = new HashMap<>();
414417
// If the two geo_points are equal, it is a point
415418
if (aggregation.topLeft().equals(aggregation.bottomRight())) {
416-
geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), PointBuilder.TYPE.shapeName());
419+
geoShape.put(FIELD_TYPE, POINT);
417420
geoShape.put(
418-
ShapeParser.FIELD_COORDINATES.getPreferredName(),
421+
FIELD_COORDINATES,
419422
Arrays.asList(aggregation.topLeft().getLon(), aggregation.bottomRight().getLat())
420423
);
421424
// If only the lat or the lon of the two geo_points are equal, than we know it should be a line
422425
} else if (Double.compare(aggregation.topLeft().getLat(), aggregation.bottomRight().getLat()) == 0
423426
|| Double.compare(aggregation.topLeft().getLon(), aggregation.bottomRight().getLon()) == 0) {
424-
geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), LineStringBuilder.TYPE.shapeName());
427+
geoShape.put(FIELD_TYPE, LINESTRING);
425428
geoShape.put(
426-
ShapeParser.FIELD_COORDINATES.getPreferredName(),
429+
FIELD_COORDINATES,
427430
Arrays.asList(
428431
new Double[] { aggregation.topLeft().getLon(), aggregation.topLeft().getLat() },
429432
new Double[] { aggregation.bottomRight().getLon(), aggregation.bottomRight().getLat() }
430433
)
431434
);
432435
} else {
433436
// neither points are equal, we have a polygon that is a square
434-
geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), PolygonBuilder.TYPE.shapeName());
437+
geoShape.put(FIELD_TYPE, POLYGON);
435438
final GeoPoint tl = aggregation.topLeft();
436439
final GeoPoint br = aggregation.bottomRight();
437440
geoShape.put(
438-
ShapeParser.FIELD_COORDINATES.getPreferredName(),
441+
FIELD_COORDINATES,
439442
Collections.singletonList(
440443
Arrays.asList(
441444
new Double[] { tl.getLon(), tl.getLat() },
@@ -468,9 +471,9 @@ public Object value(Object key, String type) {
468471
assert key instanceof String;
469472
Rectangle rectangle = GeoTileUtils.toBoundingBox(key.toString());
470473
final Map<String, Object> geoShape = new HashMap<>();
471-
geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), PolygonBuilder.TYPE.shapeName());
474+
geoShape.put(FIELD_TYPE, POLYGON);
472475
geoShape.put(
473-
ShapeParser.FIELD_COORDINATES.getPreferredName(),
476+
FIELD_COORDINATES,
474477
Collections.singletonList(
475478
Arrays.asList(
476479
new Double[] { rectangle.getMaxLon(), rectangle.getMinLat() },

0 commit comments

Comments
 (0)