-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Geo: add validator that only checks altitude (#43893)
By default, we don't check ranges while indexing geo_shapes. As a result, it is possible to index geoshapes that contain contain coordinates outside of -90 +90 and -180 +180 ranges. Such geoshapes will currently break SQL and ML retrieval mechanism. This commit removes these restriction from the validator is used in SQL and ML retrieval.
- Loading branch information
Showing
18 changed files
with
248 additions
and
11 deletions.
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
libs/geo/src/main/java/org/elasticsearch/geo/utils/StandardValidator.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,128 @@ | ||
/* | ||
* 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.geo.utils; | ||
|
||
import org.elasticsearch.geo.geometry.Circle; | ||
import org.elasticsearch.geo.geometry.Geometry; | ||
import org.elasticsearch.geo.geometry.GeometryCollection; | ||
import org.elasticsearch.geo.geometry.GeometryVisitor; | ||
import org.elasticsearch.geo.geometry.Line; | ||
import org.elasticsearch.geo.geometry.LinearRing; | ||
import org.elasticsearch.geo.geometry.MultiLine; | ||
import org.elasticsearch.geo.geometry.MultiPoint; | ||
import org.elasticsearch.geo.geometry.MultiPolygon; | ||
import org.elasticsearch.geo.geometry.Point; | ||
import org.elasticsearch.geo.geometry.Polygon; | ||
import org.elasticsearch.geo.geometry.Rectangle; | ||
|
||
/** | ||
* Validator that only checks that altitude only shows up if ignoreZValue is set to true. | ||
*/ | ||
public class StandardValidator implements GeometryValidator { | ||
|
||
private final boolean ignoreZValue; | ||
|
||
public StandardValidator(boolean ignoreZValue) { | ||
this.ignoreZValue = ignoreZValue; | ||
} | ||
|
||
protected void checkAltitude(double zValue) { | ||
if (ignoreZValue == false && Double.isNaN(zValue) == false) { | ||
throw new IllegalArgumentException("found Z value [" + zValue + "] but [ignore_z_value] " | ||
+ "parameter is [" + ignoreZValue + "]"); | ||
} | ||
} | ||
|
||
@Override | ||
public void validate(Geometry geometry) { | ||
if (ignoreZValue == false) { | ||
geometry.visit(new GeometryVisitor<Void, RuntimeException>() { | ||
|
||
@Override | ||
public Void visit(Circle circle) throws RuntimeException { | ||
checkAltitude(circle.getAlt()); | ||
return null; | ||
} | ||
|
||
@Override | ||
public Void visit(GeometryCollection<?> collection) throws RuntimeException { | ||
for (Geometry g : collection) { | ||
g.visit(this); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Void visit(Line line) throws RuntimeException { | ||
for (int i = 0; i < line.length(); i++) { | ||
checkAltitude(line.getAlt(i)); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Void visit(LinearRing ring) throws RuntimeException { | ||
for (int i = 0; i < ring.length(); i++) { | ||
checkAltitude(ring.getAlt(i)); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Void visit(MultiLine multiLine) throws RuntimeException { | ||
return visit((GeometryCollection<?>) multiLine); | ||
} | ||
|
||
@Override | ||
public Void visit(MultiPoint multiPoint) throws RuntimeException { | ||
return visit((GeometryCollection<?>) multiPoint); | ||
} | ||
|
||
@Override | ||
public Void visit(MultiPolygon multiPolygon) throws RuntimeException { | ||
return visit((GeometryCollection<?>) multiPolygon); | ||
} | ||
|
||
@Override | ||
public Void visit(Point point) throws RuntimeException { | ||
checkAltitude(point.getAlt()); | ||
return null; | ||
} | ||
|
||
@Override | ||
public Void visit(Polygon polygon) throws RuntimeException { | ||
polygon.getPolygon().visit(this); | ||
for (int i = 0; i < polygon.getNumberOfHoles(); i++) { | ||
polygon.getHole(i).visit(this); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Void visit(Rectangle rectangle) throws RuntimeException { | ||
checkAltitude(rectangle.getMinAlt()); | ||
checkAltitude(rectangle.getMaxAlt()); | ||
return null; | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
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
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
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
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
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
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
Oops, something went wrong.