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
Add Z value support to geo_point and geo_shape #25738
Conversation
} | ||
|
||
protected static void writeCoordinateTo(Coordinate coordinate, StreamOutput out) throws IOException { | ||
out.writeDouble(coordinate.x); | ||
out.writeDouble(coordinate.y); | ||
out.writeOptionalDouble(Double.isNaN(coordinate.z) ? null : coordinate.z); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to add a version check here?
return new Coordinate(in.readDouble(), in.readDouble()); | ||
double x = in.readDouble(); | ||
double y = in.readDouble(); | ||
Double z = in.readOptionalDouble(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to add a version check here?
.coordinate(new Coordinate(-45, -30, 101)) | ||
.coordinate(new Coordinate(-45, 30, 110))); | ||
|
||
assertEquals(expected, pb.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should test parsing too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added testParse3DPolygon
to GeoJSONShapeParserTests
6182333
to
bc29b96
Compare
bc29b96
to
a2118c1
Compare
@hanoch This PR effectively fixes a bug where Z values for |
52ee020
to
fdf07e0
Compare
fdf07e0
to
d9383f3
Compare
@nknize are you still working on this? |
@nknize we are still waiting for this functionality to be merged into the master branch. |
cc: @sherry-ger |
1744096
to
0a7868d
Compare
@colings86 This should be good to go. Could you give it a final once over since @jpountz is out? Thx |
Discussed this in FixItFriday. We're not crazy about accepting parameters that we will silently ignore, but given that Z values are part of the geojson spec, we should probably make an effort to extract what info we can from valid geojson files. It should, however, be enabled by opting in using a mapping parameter like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nknize this looks ok to me but could you add the option that @clintongormley mentioned and a tests with 3 dimensional polygons with and without that setting?
0a7868d
to
300fde3
Compare
are we finally ready to merge this to master anytime soon? |
@colings86 @jpountz @nknize is this now ready to be merged to master to be able to address #22917? |
7e215b5
to
e473d77
Compare
Rebased to master and cleaned up some geo_point parsing. This is ready for another review and should be just about ready to merge. /cc @jpountz @colings86 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, its a shame the changes are so pervasive in the code and the acceptZValue option has to be passed around so much but unfortunately I don't think there is a better way to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the docs very explicit about how the 3rd dimension is handled. I left some comments but it looks like it is on the right track to me.
@@ -173,6 +173,10 @@ public String toWKT() { | |||
throw new UnsupportedOperationException("The WKT spec does not support CIRCLE geometry"); | |||
} | |||
|
|||
public int numDimensions() { | |||
return center.z == Double.NaN ? 2 : 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beware it might not do what you think: https://stackoverflow.com/questions/8819738/why-does-double-nan-double-nan-return-false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yes... thank you. I still slip up w/ this one occasionally.
this.points.add(coordinate); | ||
if (points.isEmpty() == false && Double.isNaN(points.get(0).z) != Double.isNaN(coordinate.z)) { | ||
throw new ElasticsearchException("unable to add coordinate to CoordinateBuilder: " + | ||
"coordinate dimensions do not match"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the expected number of dims and the new coordinate to the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -452,12 +472,15 @@ public Query termQuery(Object value, QueryShardContext context) { | |||
|
|||
protected Explicit<Boolean> coerce; | |||
protected Explicit<Boolean> ignoreMalformed; | |||
protected Explicit<Boolean> storeZValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't seem to be making decisions based on this option? or do I miss it?
@@ -105,6 +105,13 @@ The following parameters are accepted by `geo_point` fields: | |||
If `true`, malformed geo-points are ignored. If `false` (default), | |||
malformed geo-points throw an exception and reject the whole document. | |||
|
|||
<<accept_z_value,`accept_z_value`>>:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be called something like ignore_z_value
instead to make it clear it's ignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
* @param ch the char to count | ||
* @return the number of occurrences, 0 if the CharSequence is {@code null} | ||
*/ | ||
public static int countMatches(final CharSequence str, final char ch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reading the rest of the PR, it doesn't seem like we really need this method? We could just check whether the string contains a comma to know whether it is a geohash and then use the length of the array after splitting to know the number of dimensions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
double lat = Double.NaN; | ||
double lon = Double.NaN; | ||
double alt = Double.NaN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for this alt
variable
double x = in.readDouble(); | ||
double y = in.readDouble(); | ||
Double z = null; | ||
if (in.getVersion().onOrAfter(Version.V_6_0_0_beta1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be version 6.3 now
@@ -123,6 +130,9 @@ public void writeTo(StreamOutput out) throws IOException { | |||
protected static void writeCoordinateTo(Coordinate coordinate, StreamOutput out) throws IOException { | |||
out.writeDouble(coordinate.x); | |||
out.writeDouble(coordinate.y); | |||
if (out.getVersion().onOrAfter(Version.V_6_1_0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be 6.3
if (token == XContentParser.Token.VALUE_NUMBER) { | ||
GeoPoint.assertZValue(acceptZValue); | ||
alt = parser.doubleValue(); | ||
} | ||
while (token == XContentParser.Token.VALUE_NUMBER) { | ||
token = parser.nextToken(); | ||
} | ||
// todo support z/alt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove todo
} | ||
|
||
public static class Defaults { | ||
public static final Explicit<Boolean> IGNORE_MALFORMED = new Explicit<>(false, false); | ||
public static final GeoPointFieldType FIELD_TYPE = new GeoPointFieldType(); | ||
public static final Explicit<Boolean> ACCEPT_Z_VALUE = new Explicit<>(true, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true by default? shouldn't it be false like the docs say? (we might need some logic to make it true for pre-6.3 indices in case we used to accept it in the past)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic looks good to me overall. I think we should make the default of ignore_z_value
false as it could otherwise be a bit trappy? For shapes we can do it directly in this PR since they never supported 3 dimensions (if my understanding is correct). And for points which were always lenient until now (again, if my understanding is correct), we would make the default true
in this PR (like you did) but do a follow-up PR to change the default to false
on 7.0+ indices
|
||
public GeoPoint resetFromString(String value, final boolean ignoreZValue) { | ||
if (value.contains(",")) { | ||
String[] vals = value.split(","); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fail if vals.length > 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -100,6 +100,7 @@ | |||
public static final double LEGACY_DISTANCE_ERROR_PCT = 0.025d; | |||
public static final Explicit<Boolean> COERCE = new Explicit<>(false, false); | |||
public static final Explicit<Boolean> IGNORE_MALFORMED = new Explicit<>(false, false); | |||
public static final Explicit<Boolean> ACCEPT_Z_VALUE = new Explicit<>(true, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/ACCEPT/IGNORE/
double alt = Double.NaN; | ||
if (token == XContentParser.Token.VALUE_NUMBER) { | ||
alt = GeoPoint.assertZValue(ignoreZValue, parser.doubleValue()); | ||
} | ||
while (token == XContentParser.Token.VALUE_NUMBER) { | ||
token = parser.nextToken(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove this leniency?
@jpountz @nknize what is the overall design goal wrt the default behavior with Z values with geo_shape and geo_point? |
@hanoch we do not want the Z Values to be accepted by default because it can be surprising to users. The fact that the z value is accepted but is not indexed and therefore does not affect search results is not what a user would expect OOTB so we feel it is a better user experience for the user to opt-in to accepting but ignoring the Z-Value. |
is there anything else pending or are we ready to merge this PR? |
05cc21a
to
59c65a6
Compare
This enhancement adds Z value support (source only) to geo_shape fields. If vertices are provided with a third dimension, the third dimension is ignored for indexing but returned as part of source. Like beofre, any values greater than the 3rd dimension are ignored. closes elastic#23747
59c65a6
to
fede633
Compare
This enhancement adds Z value support (source only) to geo_shape fields. If vertices are provided with a third dimension, the third dimension is ignored for indexing but returned as part of source. Like before, any values greater than the 3rd dimension are ignored.
closes #22917