-
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
Refactoring of GeoBoundingBoxQueryBuilder and -Parser #11969
Refactoring of GeoBoundingBoxQueryBuilder and -Parser #11969
Conversation
This is very much work in progress. Posting the PR mostly to seek input on how to proceed with testing toQuery in the type="indexed" setting: Running as is it complains in the following assertion - trying to fix the assertion by providing the needed dependencies through Guice in our test setup felt like this would be easier to do in an ElasticsearchIntegration/SingleNodeTest. There must be some simpler option to be able to run the toQuery method in a test harness that doesn't need a cluster spun up which I don't see? java.lang.AssertionError |
private double[] box = {Double.NaN, Double.NaN, Double.NaN, Double.NaN}; | ||
|
||
private String queryName; | ||
private String type; | ||
private String fieldName; |
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 can still be final no?
@MaineC this is one of the few cases that might make it very hard to test things without a node. I need to look into this deeper. Can you leave out for now that specific case in testing, we can look at it while the rest is ready. |
Sure - no problem. Leaving it out is a matter of not setting the type to "indexed" when creating the test query builders. I'll also open an issue as a reminder to get back to this test if you don't mind. |
14ae9ea
to
47506cb
Compare
Rebased, took the failing test out, added validation - some test setup for query creation still failing. Digging. Missing: cleanup. |
Note: Keep #12016 in mind for the test setup. |
47506cb
to
a476427
Compare
I believe this is ready for a first round of feedback. Here's what I did:
The previous bounding box test still passes, so does the newly added one (as well as anything that runs with mvn clean install). Caveat: Neither test checks the type=memory code path. @nik9000 I've been told that you are the Geo Magician - would be great if you could double check what I've done and point out any mistakes as well. Note: I've left the refactoring steps in separate commits for now if you want to look at them separately to see which step introduced which change. |
Too many Niks - thanks for correcting me. :) |
Just skimmed (didn't look particularly deep at all) the changes with @cbuescher - it might make sense to move the geo point/ geo bounding box validation methods into a separate class so it can be used elsewhere. Same for the geo point/ box generation code in the test methods. Both - random point generation in the test and validation in the builder are candidates where I would appreciate input from @nknize - I believe all the rest should be standard query refactoring stuff. |
} else if (Type.MEMORY.equals(type)) { | ||
IndexGeoPointFieldData indexFieldData = parseContext.getForField(fieldType); | ||
result = new InMemoryGeoBoundingBoxQuery(topLeft, bottomRight, indexFieldData); | ||
} else { |
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.
Was wondering if with the Type enum, is this final else check necessary?
Current state: Rebased, updated according to both comments, squashed. When running the tests from the command line with a "mvn clean install -Dtests.jvms=4" with JAVA_HOME set to /home/isabel/bin/jdk1.8.0_60/ the following two tests are failing reproducably for me:
Checking what's wrong at the moment. (After running the same on the feature/query-refactoring branch:
is failing there. As CI for our branch is silent I assume there's something off with my current setup.) |
I think that has to do with your test name. All the test now have to end in "_Tests" instead of "_Test", that should take care of this error. |
5b758bb
to
166e9fb
Compare
Rebased, squashed, fixed failing tests (thanks @cbuescher for the pointer, the other failure indeed was an issue with my machine's setup). |
/** | ||
* Sets the type of executing of the geo bounding box. Can be either `memory` or `indexed`. Defaults | ||
* to `memory`. | ||
*/ | ||
public GeoBoundingBoxQueryBuilder type(GeoExecType type) { | ||
this.type = (type != null) ? type : DEFAULT_TYPE; |
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.
I started changing the setters that turn null into default value back to throwing IAE, parser shouldn't allow null type value here either. But we can also do that later.
@MaineC did a quick round, left a few minor comments but I think this is ready, unless you want to give it another look or want someone else to have a look at it again. |
166e9fb
to
07bb317
Compare
Rebased, squashed, fixed the issues @cbuescher found. |
@MaineC heads up, I just pushed the GeoDistanceQueryBuilder refactoring you reviewed, so this PR probably needs one more rebasing, but other than that I think it is ready to go in. |
07bb317
to
902ddf5
Compare
/** | ||
* For serialization only. | ||
* */ | ||
private GeoBoundingBoxQueryBuilder() { |
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 just pass an empty string to the ctor with a fieldName for the prototype
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 do, but then I can't check/throw an exception in the constructor if the fieldName argument is an empty string. See change for illustration.
left some comments LGTM otherwise |
Thanks for the review. Done fixing most of your comments, about to fix the now failing validation tests. |
902ddf5
to
d6382bd
Compare
@s1monw Addressed your comments. Re-organised some tests as a result (and fixed several issues the original tests had which I hadn't spotted when re-reading them over and over again), rebased and squashed. |
LGTM |
This add equals, hashcode, read/write methods, validation, separates toQuery and JSON parsing and adds serialization and query generation tests. Deprecates two types of initializing the bounding box: In our documentation we speak about specifying top/left and bottom/right corner of a bounding box. Here we also allow for top/right and bottom/left. This adds not only to the amount of code but also testing needed w/o too much benefit for the user other than more chances to confuse top/right/bottom/left/latitude/longitude IMHO. Missing: The toQuery method with type set to "indexed" is not tested at the moment. Cleanup changes unrelated to base refactoring: * Switched from type String to enum for types in GeoBoundingBoxQueryBuilder. * Switched to using type GeoPoint for storing the bounding box coordinates instead of array of double values. Relates to elastic#10217 for the query refactoring part. Relates to elastic#12016 for how missing mappings are handled. Adds a utility class for generating random geo data. Adds some missing documentation. Extend test to MEMORY type config Fix final review comments and rebase
d6382bd
to
91b97a6
Compare
…oring Refactoring of GeoBoundingBoxQueryBuilder and -Parser
... -Builder/-Parser. This add equals, hashcode, read/write methods, separates toQuery and JSON parsing and adds first tests.
Deprecates two types of initializing the bounding box: In our documentation we speak about specifying top/left and bottom/right corner of a bounding box. Here we also allow for top/right and bottom/left. This adds not only to the amount of code but also testing needed w/o too much benefit for the user other than more chances to confuse top/right/bottom/left/latitude/longitude IMHO.
Missing: validation, there are some easy opportunities for cleaning parser and builder.
The test path that checks the toQuery method if type is set to "indexed" fails at the moment due to missing Guice initialisations. I tried to add everything needed but felt like the result looked a lot like it would actually like to be an ElasticsearchSingleNodeTest so not sure how to proceed here?
Relates to #10217