-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Refactored geogrid to support multiple hash types #30320
Changes from all commits
8795e95
d8245b7
5cbad00
2fa03c3
cf724e9
8115690
82dd82d
06d87de
f5f56ba
689dffc
8effe02
32a8725
a26a588
b54f832
9b3668d
040f889
54ef54e
d95c6a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -32,7 +32,6 @@ | |||
import org.elasticsearch.common.xcontent.XContentParser; | ||||
import org.elasticsearch.common.xcontent.XContentParser.Token; | ||||
import org.elasticsearch.common.xcontent.json.JsonXContent; | ||||
import org.elasticsearch.common.xcontent.support.XContentMapValues; | ||||
import org.elasticsearch.index.fielddata.FieldData; | ||||
import org.elasticsearch.index.fielddata.GeoPointValues; | ||||
import org.elasticsearch.index.fielddata.MultiGeoPointValues; | ||||
|
@@ -548,23 +547,26 @@ private static GeoPoint parseGeoHash(GeoPoint point, String geohash, EffectivePo | |||
* @return int representing precision | ||||
*/ | ||||
public static int parsePrecision(XContentParser parser) throws IOException, ElasticsearchParseException { | ||||
XContentParser.Token token = parser.currentToken(); | ||||
if (token.equals(XContentParser.Token.VALUE_NUMBER)) { | ||||
return XContentMapValues.nodeIntegerValue(parser.intValue()); | ||||
} else { | ||||
String precision = parser.text(); | ||||
return parser.currentToken() == Token.VALUE_NUMBER ? parser.intValue() : parsePrecisionString(parser.text()); | ||||
} | ||||
|
||||
/** | ||||
* Attempt to parse geohash precision string into an integer value | ||||
*/ | ||||
public static int parsePrecisionString(String precision) { | ||||
try { | ||||
// we want to treat simple integer strings as precision levels, not distances | ||||
return checkPrecisionRange(Integer.parseInt(precision)); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a breaking change here. We can only do this in 7.0.0 but I suspect you are going to want to backport this PR to the 6.x branch. I think we should change this here to warn if the precision is out of range using the deprecation logger and then we can have a follow up PR for 7.0 only that makes this strictly within the range. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you sure there are changes from the previous algorithm? I simply broke up the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its a breaking change because if the string in the JSON was a simple integer value before we would parse it to an int using The question is, what used to happen is you gave a precision value outside of the range? Did we fail later in execution (in which case the breaking change here might be ok)? Did we accept the precision value and process it at the precision specified even though its outside the range? or may we accepted the precision value and if it was outside the range we used it as if it was at one of the bounds (i.e. if the value is above the MAX_PRECISION we just evaluated it as if it was MAX_PRECISION)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @colings86 i think you misunderstood my comment - the existing code already throws an error if precision is out of range -- Line 116 in 2c20f7a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, in which case I agree that this is not a breaking change |
||||
// checkPrecisionRange could also throw IllegalArgumentException, but let it through | ||||
// to keep errors somewhat consistent with how they were shown before this change | ||||
} catch (NumberFormatException e) { | ||||
// try to parse as a distance value | ||||
final int parsedPrecision = GeoUtils.geoHashLevelsForPrecision(precision); | ||||
try { | ||||
// we want to treat simple integer strings as precision levels, not distances | ||||
return XContentMapValues.nodeIntegerValue(precision); | ||||
} catch (NumberFormatException e) { | ||||
// try to parse as a distance value | ||||
final int parsedPrecision = GeoUtils.geoHashLevelsForPrecision(precision); | ||||
try { | ||||
return checkPrecisionRange(parsedPrecision); | ||||
} catch (IllegalArgumentException e2) { | ||||
// this happens when distance too small, so precision > 12. We'd like to see the original string | ||||
throw new IllegalArgumentException("precision too high [" + precision + "]", e2); | ||||
} | ||||
return checkPrecisionRange(parsedPrecision); | ||||
} catch (IllegalArgumentException e2) { | ||||
// this happens when distance too small, so precision > 12. We'd like to see the original string | ||||
throw new IllegalArgumentException("precision too high [" + precision + "]", e2); | ||||
} | ||||
} | ||||
} | ||||
|
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 we check here that a search returns the expected response so if it fails on the mixed cluster test we know the problem is to do with the upgrade and not because something went wrong on the old cluster before the upgrade?
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.
done