-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support cartesian_bounds aggregation on point and shape (#91298)
* Support cartesian_bounds aggregation on point and shape * Update docs/changelog/91298.yaml * Update docs/changelog/91298.yaml * Fixed cartesian parse exceptions to mimic previous behavior * Re-added removed interfaces to fix failing tests * Generalized AbstractGeoTestCase for use in Cartesian tests And added new CartesianBoundsIT and CartesianCentroidIT * Fixed bug in encoding missing cartesian points * Simplify cartesian bounds * Removing the neg/pos left/right split used in bounds because this is only relevant to GeoBounds * Revert GeoBounds to no longer share common code with CartesianBounds (including aggregators) * Make Point and Shape aggregators share common code * Fixed geo comment * Delete incorrectly added file * Set correct minimum version for new cartesian aggs * Fixed specific types for ShapeValues * Completed Centroid/Bounds aggregation integration tests refactoring An earlier commit started generalizing Geo/Cartesian integration tests for centroid and bounds aggregations, but did not complete the job. This commit completes the work, since almost all tests are identical between cartesian and geo, except tests related to the dateline. * Removed licensing comment * GeoBoundsIT expects wrapLongitude(false) * Fixed CartesianBoundsIT flakiness and removed geo-specific code * Reduced CartesianCentroidIT flakiness by normalizing to floats
- Loading branch information
1 parent
5cb0905
commit 34e8da6
Showing
41 changed files
with
2,589 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 91298 | ||
summary: Support `cartesian_bounds` aggregation on point and shape | ||
area: Geo | ||
type: enhancement | ||
issues: | ||
- 90157 |
252 changes: 58 additions & 194 deletions
252
...c/internalClusterTest/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsIT.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
server/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalBounds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.search.aggregations.metrics; | ||
|
||
import org.elasticsearch.common.geo.BoundingBox; | ||
import org.elasticsearch.common.geo.GeoBoundingBox; | ||
import org.elasticsearch.common.geo.SpatialPoint; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.search.aggregations.InternalAggregation; | ||
import org.elasticsearch.search.aggregations.support.SamplingContext; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public abstract class InternalBounds<T extends SpatialPoint> extends InternalAggregation implements SpatialBounds<T> { | ||
public final double top; | ||
public final double bottom; | ||
|
||
public InternalBounds(String name, double top, double bottom, Map<String, Object> metadata) { | ||
super(name, metadata); | ||
this.top = top; | ||
this.bottom = bottom; | ||
} | ||
|
||
/** | ||
* Read from a stream. | ||
*/ | ||
public InternalBounds(StreamInput in) throws IOException { | ||
super(in); | ||
top = in.readDouble(); | ||
bottom = in.readDouble(); | ||
} | ||
|
||
@Override | ||
protected void doWriteTo(StreamOutput out) throws IOException { | ||
out.writeDouble(top); | ||
out.writeDouble(bottom); | ||
} | ||
|
||
@Override | ||
public InternalAggregation finalizeSampling(SamplingContext samplingContext) { | ||
return this; | ||
} | ||
|
||
@Override | ||
protected boolean mustReduceOnSingleInternalAgg() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Object getProperty(List<String> path) { | ||
if (path.isEmpty()) { | ||
return this; | ||
} else if (path.size() == 1) { | ||
BoundingBox<T> bbox = resolveBoundingBox(); | ||
String bBoxSide = path.get(0); | ||
return switch (bBoxSide) { | ||
case "top" -> bbox.top(); | ||
case "left" -> bbox.left(); | ||
case "bottom" -> bbox.bottom(); | ||
case "right" -> bbox.right(); | ||
default -> throw new IllegalArgumentException("Found unknown path element [" + bBoxSide + "] in [" + getName() + "]"); | ||
}; | ||
} else if (path.size() == 2) { | ||
BoundingBox<T> bbox = resolveBoundingBox(); | ||
T cornerPoint = null; | ||
String cornerString = path.get(0); | ||
cornerPoint = switch (cornerString) { | ||
case "top_left" -> bbox.topLeft(); | ||
case "bottom_right" -> bbox.bottomRight(); | ||
default -> throw new IllegalArgumentException("Found unknown path element [" + cornerString + "] in [" + getName() + "]"); | ||
}; | ||
return selectCoordinate(path.get(1), cornerPoint); | ||
} else { | ||
throw new IllegalArgumentException("path not supported for [" + getName() + "]: " + path); | ||
} | ||
} | ||
|
||
protected abstract Object selectCoordinate(String coordinateString, T cornerPoint); | ||
|
||
@Override | ||
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { | ||
BoundingBox<T> bbox = resolveBoundingBox(); | ||
if (bbox != null) { | ||
builder.startObject(GeoBoundingBox.BOUNDS_FIELD.getPreferredName()); | ||
bbox.toXContentFragment(builder); | ||
builder.endObject(); | ||
} | ||
return builder; | ||
} | ||
|
||
protected abstract BoundingBox<T> resolveBoundingBox(); | ||
|
||
@Override | ||
public T topLeft() { | ||
BoundingBox<T> bbox = resolveBoundingBox(); | ||
if (bbox == null) { | ||
return null; | ||
} else { | ||
return bbox.topLeft(); | ||
} | ||
} | ||
|
||
@Override | ||
public T bottomRight() { | ||
BoundingBox<T> bbox = resolveBoundingBox(); | ||
if (bbox == null) { | ||
return null; | ||
} else { | ||
return bbox.bottomRight(); | ||
} | ||
} | ||
} |
Oops, something went wrong.