-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Query Refactoring: ExistsQueryBuilder and Parser #11427
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
Query Refactoring: ExistsQueryBuilder and Parser #11427
Conversation
I'm still not 100% happy with the test for the query generation (toQuery) since constructing the expected Lucene query relies on using newFilter() helper method. Testing that helper method itself would require a lot of repetition of inner implementation logic in the creating of the expected query, so I choose not to go into that for now. Since it's a static method, maybe that would be better handled in a separate integration test? |
|
||
/** | ||
* | ||
*/ | ||
public class ExistsQueryParser extends BaseQueryParserTemp { | ||
public class ExistsQueryParser extends BaseQueryParser { | ||
|
||
@Inject |
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.
Is the annotation needed on a constructor w/o arguments?
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 so, at least we have it on a couple of other no-arg parsers. I'll try what happens when I remove them but I guess it messes up some guice registry stuff.
3febb94
to
dfa90fa
Compare
Extended test for the toQuery() part of the ExistsQueryBuilder. Setup now randomly disables FieldNamesFieldMapper so we cover more execution paths. |
final FieldNamesFieldMapper fieldNamesMapper = (FieldNamesFieldMapper)parseContext.mapperService().fullName(FieldNamesFieldMapper.NAME); | ||
|
||
MapperService.SmartNameObjectMapper smartNameObjectMapper = parseContext.smartObjectMapper(fieldPattern); | ||
if (smartNameObjectMapper != null && smartNameObjectMapper.hasMapper()) { |
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 couldn't find out yet how to test this branch. I'll try to find out what it actually does and find a way to insert SmartNameObjectMapper into parseContext in out setup.
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.
Changed test setup with recent commit so this is covered now.
dfa90fa
to
46540d5
Compare
@@ -266,7 +284,10 @@ public void testSerialization() throws IOException { | |||
* @return a new {@link QueryParseContext} based on the base test index and queryParserService | |||
*/ | |||
protected static QueryParseContext createContext() { | |||
return new QueryParseContext(index, queryParserService); | |||
QueryParseContext context = new QueryParseContext(index, queryParserService); | |||
QueryParseContext.setTypes(currentTypes); |
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.
mmm don't we have this somewhere else already? being it static, we shouldn't do it every time we create a new context, only once
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.
Right, I missed that we have similar setup in beforeTest(). Reverted this.
looks good, left a few comments |
46540d5
to
e0393da
Compare
@javanna Thanks, adressed your last comments and rebased on current head of feature branch. |
e0393da
to
ed335b2
Compare
@@ -41,6 +54,13 @@ public ExistsQueryBuilder(String name) { | |||
} | |||
|
|||
/** | |||
* @return the field name that has to exists for this query to 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.
s/exists/exist
I left a couple of minor comments, LGTM though, feel free to push once you addressed those |
ed335b2
to
10a3fe1
Compare
Rebasing on current head of feature branch and addressing last round of comments. |
@@ -125,7 +135,7 @@ protected void configure() { | |||
queryParserService = injector.getInstance(IndexQueryParserService.class); | |||
MapperService mapperService = queryParserService.mapperService; | |||
//create some random type with some default field, those types will stick around for all of the subclasses | |||
currentTypes = new String[randomIntBetween(0, 5)]; | |||
currentTypes = new String[randomIntBetween(1, 5)]; |
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 temporarily changed this to add at least one type plus mappings because so far in our test setup the FieldNamesFieldMapper which we now need to be non-null in ExistQueryBuilder is initiallized only when triggered by the mapperService.merge. Before there were null checks in the ExistQueryParser/Builder newFilter() method that now got removed on master. Still looking for other ways to change the test setup here.
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.
It kinda makes sense to me that the field is not there if we have no types (aka the index is empty). This is exactly why I want to keep testing against no types. I think this is a bug introduced with #11559 where a null check was removed (1fdae75#commitcomment-11609013). The FieldNamesFieldMapper can be null and we should handle such situation properly. Once that gets fixed upstream our tests can still use no types randomly I think.
left two comments, LGTM though. We have to resolve upstream the problem around FieldNamesFieldMapper and we are good to go I'd say. |
Added randomization of the version in settings, will wait hearing back about possible upstream changes. |
…text ctx) method into a parsing and a query building part, adding NamedWriteable implementation for serialization and hashCode(), equals() for testing. This change also adds tests using fixed set of leaf queries (Terms, Ids, MatchAll) as nested Queries in test query setup. Also QueryParseContext is adapted to return QueryBuilder instances for inner filter parses instead of previously returning Query instances, keeping old methods in place but deprecating them. Relates to elastic#10217 Closes elastic#11427
97900c9
to
6700261
Compare
Refactors ExistsQueryBuilder and Parser, splitting the parse() method into a parsing and a query building part. Also moving newFilter() utility method from parser to query builder. Changes in the BaseQueryTestCase include introduction of randomized version to test disabled FieldNamesFieldMappers and also getting rid of the need for createEmptyBuilder() method by using registered prototype constants. Relates to elastic#10217 Closes elastic#11427
6700261
to
c928852
Compare
LGTM |
…ists Query Refactoring: ExistsQueryBuilder and Parser
…text ctx) method into a parsing and a query building part, adding NamedWriteable implementation for serialization and hashCode(), equals() for testing. This change also adds tests using fixed set of leaf queries (Terms, Ids, MatchAll) as nested Queries in test query setup. Also QueryParseContext is adapted to return QueryBuilder instances for inner filter parses instead of previously returning Query instances, keeping old methods in place but deprecating them. Relates to elastic#10217 Closes elastic#11427
Refactors ExistsQueryBuilder and Parser, splitting the parse() method into a parsing and a query building part. Also moving newFilter() utility method from parser to query builder. Changes in the BaseQueryTestCase include introduction of randomized version to test disabled FieldNamesFieldMappers and also getting rid of the need for createEmptyBuilder() method by using registered prototype constants. Relates to elastic#10217 Closes elastic#11427
…ring-exists Query Refactoring: ExistsQueryBuilder and Parser
Refactors ExistsQueryBuilder and Parser, splitting the parse() method into a parsing and a query building part. Also moving newFilter() uitlity method from parser to query builder.
Changes in the BaseQueryTestCase include introduction of randomized version to test disabled FieldNamesFieldMappers and also getting rid of the need for createEmptyBuilder() method by now using existing prototype constants.
Relates to #10217
PR goes agains query-refacoring feature branch.