-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Rework a query parser and improve registration #17458
Conversation
Another one for @javanna and @cbuescher. Two more queries down out of about 45. |
@@ -310,15 +305,33 @@ public void registerFunctionScoreParser(ScoreFunctionParser<? extends ScoreFunct | |||
* registered. So it is the name that the query should use as its {@link NamedWriteable#getWriteableName()}. | |||
*/ | |||
public <QB extends QueryBuilder<QB>> void registerQuery(Writeable.Reader<QB> reader, QueryParser<QB> parser, String... names) { |
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 doesn't directly concern changes in this PR, but the first name should be mandatory here. What about making this signature String queryName, String alternativeNames
or something along those lines?
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.
that is a good point Christoph! if we really want to keep varargs otherwise we could validate that the array has length >=1 , I have no strong preference on how we solve it though
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 think we should make sure that the String that is used as Id in serialization gets treated in a special way, also in the builders themselves so they are not accidentally changed between versions. Thats why I liked the old getWritableName()
(that seems to be on its way out).
Maybe we should even have an own class QueryId
which simply wraps the NAME string constant but forces us (and users implementing their own queries) to think about this as a special case. We could change the existing String getName()
method in QueryBuilder
that currenty just forwards to getWritableName
to do this.
This is just some thought for discussion, nothing to block this PR though.
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 agree with you 100% we have to be more careful with query ids and serialization problems. With this change we hide even more that the first name is used for serialization, maybe we can already split the two (parser names and writeable id) more clearly instead, I would go that path.
@nik9000 I left a small comment about a missing name constant and some general thought about whether we should keep some of the query identifiers in their respective classes for discussion. |
@cbuescher, @javanna, @colings86 and I had a video chat about this and talked about this and we were uncomfortable with the way in which we supported query alternative names and how we just relied on the first name being the getWriteableName by convention. I added a few patches to address those concerns. Hopefully this is better now! |
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static java.util.Collections.unmodifiableList; | ||
|
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 remove these redundant imports please?
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.
Sorry, sure.
thanks a lot Nik I left my random thoughts, let's see what Colin and Christoph have to say ;) |
* Randomize the name of a query builder. Note that this can change the meaning of the query builder. Like <code>match</code> can turn | ||
* into <code>match_phrase</code>. | ||
*/ | ||
private XContentBuilder randomizeName(XContentBuilder builder, QueryBuilder<?> query) throws IOException { |
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 like this test, however this won't catch any accidental or unknowing changes (like removing or changing the primary name for example) from any developer. I think in addition we should explicitely check the NAME/NAMES constants in each individual test and have some comments / errors that prevent any accidental changes. Like we do for enum constants in some tests already. We can add those in follow up PRs for all queries though.
@nik9000 I think after recent changes this should easily become a simple MultiMatchQueryParser rework. regarding the test for alternate query names, I think that what we have in SearchModuleTests is good enough. ping me when you have rebased and I will review. |
By default queries now register using both their snake_case and camelCase name. We no longer need to delay construction of the parser map so we can throw out QueryRegistration and no longer need Suppliers.
Note that this testing only works well on queries that have been cut over to the new registration API. Fixes GeohashCellQuery to match our conventions so we can find it's names.
QueryBuilder's can go by lots of names as we were using a String[] to refer to them all. The trouble is that some of the names are special and String[] doesn't let us easilly describe or document how they are special. So this adds QueryBuilder.Names. It gives us an easy place to document how the names are special and it gives us something we can build on, if, say, we want to register some of the names as deprecated or something like that.
d485702
to
9dee07b
Compare
@@ -326,8 +315,8 @@ public void registerFunctionScoreParser(ScoreFunctionParser<? extends ScoreFunct | |||
} | |||
|
|||
/** | |||
* Register a query. | |||
* TODO remove this in favor of registerQuery and rename innerRegisterQueryParser | |||
* Register a query via it's parser's 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.
s/it's/its I think
left a tiny comment, LGTM though, no need for another review |
Closed by 1afc9b7. |
By default queries now register using both their snake_case and camelCase
name. We no longer need to delay construction of the parser map so we can
throw out QueryRegistration and no longer need Suppliers.