-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add bounds support for geogrid agg on shapes #51973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
talevy
merged 15 commits into
elastic:geoshape-doc-values
from
talevy:gdv-shape-grid-bounds
Mar 2, 2020
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d537b33
Add bounds support for geogrid agg on shapes
talevy 6d7d8d6
fix behavior of tree relate
talevy d4d99f4
Merge branch 'geoshape-doc-values' into gdv-shape-grid-bounds
talevy b0de38e
small cleanup
talevy 38c508d
Fix checkstyle
talevy 4ae9e67
in silico
talevy ef26c35
Merge remote-tracking branch 'elastic/geoshape-doc-values' into gdv-s…
talevy fcc52f7
fix tests
talevy 805eb5a
remove unused test code
talevy 1741d0e
fix checkstyle
talevy 0d60301
Merge remote-tracking branch 'elastic/geoshape-doc-values' into gdv-s…
talevy 80d1a25
Merge remote-tracking branch 'elastic/geoshape-doc-values' into gdv-s…
talevy 25d694e
Merge remote-tracking branch 'elastic/geoshape-doc-values' into gdv-s…
talevy a62474e
Refactor to make Bounded Tilers
talevy cedc60d
fix geohash and other edge case tests
talevy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
121 changes: 121 additions & 0 deletions
121
.../java/org/elasticsearch/search/aggregations/bucket/geogrid/BoundedGeoShapeCellValues.java
This file contains hidden or 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,121 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.search.aggregations.bucket.geogrid; | ||
|
||
import org.elasticsearch.common.geo.DimensionalShapeType; | ||
import org.elasticsearch.common.geo.GeoBoundingBox; | ||
import org.elasticsearch.common.geo.GeoRelation; | ||
import org.elasticsearch.geometry.Rectangle; | ||
import org.elasticsearch.index.fielddata.MultiGeoValues; | ||
|
||
/** | ||
* A bounded representation of {@link UnboundedGeoShapeCellValues} | ||
*/ | ||
class BoundedGeoShapeCellValues extends UnboundedGeoShapeCellValues { | ||
private BoundedGeoValue boundedGeoValue; | ||
|
||
protected BoundedGeoShapeCellValues(MultiGeoValues geoValues, int precision, GeoGridTiler tiler, GeoBoundingBox geoBoundingBox) { | ||
super(geoValues, precision, tiler); | ||
this.boundedGeoValue = new BoundedGeoValue(geoBoundingBox); | ||
} | ||
|
||
@Override | ||
int advanceValue(MultiGeoValues.GeoValue target, int valuesIdx) { | ||
boundedGeoValue.reset(target); | ||
return super.advanceValue(boundedGeoValue, valuesIdx); | ||
} | ||
|
||
static class BoundedGeoValue implements MultiGeoValues.GeoValue { | ||
private MultiGeoValues.GeoValue innerValue; | ||
private final double boundsTop; | ||
private final double boundsBottom; | ||
private final double boundsWestLeft; | ||
private final double boundsWestRight; | ||
private final double boundsEastLeft; | ||
private final double boundsEastRight; | ||
private final boolean crossesDateline; | ||
|
||
BoundedGeoValue(GeoBoundingBox geoBoundingBox) { | ||
this.innerValue = null; | ||
|
||
// split geoBoundingBox into west and east boxes | ||
boundsTop = geoBoundingBox.top(); | ||
boundsBottom = geoBoundingBox.bottom(); | ||
if (geoBoundingBox.right() < geoBoundingBox.left()) { | ||
boundsWestLeft = -180; | ||
boundsWestRight = geoBoundingBox.right(); | ||
boundsEastLeft = geoBoundingBox.left(); | ||
boundsEastRight = 180; | ||
crossesDateline = true; | ||
} else { // only set east bounds | ||
boundsEastLeft = geoBoundingBox.left(); | ||
boundsEastRight = geoBoundingBox.right(); | ||
boundsWestLeft = 0; | ||
boundsWestRight = 0; | ||
crossesDateline = false; | ||
} | ||
} | ||
|
||
void reset(MultiGeoValues.GeoValue innerValue) { | ||
this.innerValue = innerValue; | ||
} | ||
|
||
@Override | ||
public GeoRelation relate(Rectangle rectangle) { | ||
if (boundsTop >= rectangle.getMinY() && boundsBottom <= rectangle.getMaxY() | ||
&& (boundsEastLeft <= rectangle.getMaxX() && boundsEastRight >= rectangle.getMinX() | ||
|| (crossesDateline && boundsWestLeft <= rectangle.getMaxX() && boundsWestRight >= rectangle.getMinX()))) { | ||
GeoRelation relation = innerValue.relate(rectangle); | ||
// bounded relations can never be sure to be inside until each tile and sub-tile is checked | ||
// explicitly against the geoBoundingBox | ||
if (relation == GeoRelation.QUERY_INSIDE) { | ||
return GeoRelation.QUERY_CROSSES; | ||
} | ||
return relation; | ||
} else { | ||
return GeoRelation.QUERY_DISJOINT; | ||
} | ||
} | ||
|
||
@Override | ||
public double lat() { | ||
return innerValue.lat(); | ||
} | ||
|
||
@Override | ||
public double lon() { | ||
return innerValue.lon(); | ||
} | ||
|
||
@Override | ||
public MultiGeoValues.BoundingBox boundingBox() { | ||
return innerValue.boundingBox(); | ||
} | ||
|
||
@Override | ||
public DimensionalShapeType dimensionalShapeType() { | ||
return innerValue.dimensionalShapeType(); | ||
} | ||
|
||
@Override | ||
public double weight() { | ||
return innerValue.weight(); | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.