Skip to content

Conversation

cbuescher
Copy link
Member

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.

@cbuescher
Copy link
Member Author

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
Copy link

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?

Copy link
Member Author

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.

@cbuescher cbuescher force-pushed the feature/query-refactoring-exists branch 2 times, most recently from 3febb94 to dfa90fa Compare June 4, 2015 11:38
@cbuescher
Copy link
Member Author

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()) {
Copy link
Member Author

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.

Copy link
Member Author

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.

@cbuescher cbuescher force-pushed the feature/query-refactoring-exists branch from dfa90fa to 46540d5 Compare June 5, 2015 13:21
@@ -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);
Copy link
Member

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

Copy link
Member Author

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.

@javanna
Copy link
Member

javanna commented Jun 5, 2015

looks good, left a few comments

@cbuescher cbuescher force-pushed the feature/query-refactoring-exists branch from 46540d5 to e0393da Compare June 8, 2015 14:02
@cbuescher
Copy link
Member Author

@javanna Thanks, adressed your last comments and rebased on current head of feature branch.

@cbuescher cbuescher force-pushed the feature/query-refactoring-exists branch from e0393da to ed335b2 Compare June 8, 2015 15:19
@@ -41,6 +54,13 @@ public ExistsQueryBuilder(String name) {
}

/**
* @return the field name that has to exists for this query to match
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/exists/exist

@javanna
Copy link
Member

javanna commented Jun 9, 2015

I left a couple of minor comments, LGTM though, feel free to push once you addressed those

@cbuescher cbuescher force-pushed the feature/query-refactoring-exists branch from ed335b2 to 10a3fe1 Compare June 10, 2015 10:50
@cbuescher
Copy link
Member Author

Rebasing on current head of feature branch and addressing last round of comments.
I needed to adapt the BaseQueryTest setup a bit to conform with current changes merged in from master concerning Mappings, especially FieldNameFieldMapper. See inline comment for explication.

@@ -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)];
Copy link
Member Author

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.

Copy link
Member

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.

@javanna
Copy link
Member

javanna commented Jun 10, 2015

left two comments, LGTM though. We have to resolve upstream the problem around FieldNamesFieldMapper and we are good to go I'd say.

@cbuescher
Copy link
Member Author

Added randomization of the version in settings, will wait hearing back about possible upstream changes.

cbuescher pushed a commit to cbuescher/elasticsearch that referenced this pull request Jun 11, 2015
…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
@cbuescher cbuescher force-pushed the feature/query-refactoring-exists branch from 97900c9 to 6700261 Compare June 11, 2015 11:40
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
@cbuescher cbuescher force-pushed the feature/query-refactoring-exists branch from 6700261 to c928852 Compare June 11, 2015 12:41
@javanna
Copy link
Member

javanna commented Jun 11, 2015

LGTM

cbuescher added a commit that referenced this pull request Jun 11, 2015
…ists

Query Refactoring: ExistsQueryBuilder and Parser
@cbuescher cbuescher merged commit bd2e163 into elastic:feature/query-refactoring Jun 11, 2015
@kevinkluge kevinkluge removed the review label Jun 11, 2015
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
…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
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
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
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
…ring-exists

Query Refactoring: ExistsQueryBuilder and Parser
@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Query Refactoring labels Feb 14, 2018
@cbuescher cbuescher deleted the feature/query-refactoring-exists branch March 20, 2024 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants