Skip to content
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

Refactors TermsQueryBuilder and Parser #12042

Conversation

alexksikes
Copy link
Contributor

Refactors TermsQueryBuilder and Parser for #10217. Also removes deprecated
TermsLookupQuery class and unused or deprecated options execution,
min_should_match, lookup_cache.

This PR is against the query-refactoring branch.

* @param objs the Iterable of input object
* @return the same input or a list of utf8 string if input was a list of type {@link BytesRef}
*/
protected static List<Object> convertToStringListIfBytesRefList(Iterable objs) {
Copy link
Member

Choose a reason for hiding this comment

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

not a big fan of these two new methods to be honest. Maybe since they are needed in one query only we can loop there instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not a big fan either, but note we do use convertToStringListIfBytesRefList in two places. So I moved them to the builder instead.

Copy link
Member

Choose a reason for hiding this comment

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

so the alternative is looping in two places instead in TermsQueryBuilder? I think I would go for that.

@javanna
Copy link
Member

javanna commented Aug 7, 2015

I did a first review, can you please rebase and address comments? Also, I would like to know from @s1monw and @jpountz what they think about having a Client within IndexQueryParseService, like we are adding here, so that we can retrieve it through QueryShardContext and execute the needed get calls (still on the data node). Wonder if there's any other/better way, I couldn't come up with any.

@alexksikes
Copy link
Contributor Author

@javanna Thanks for the review. Just a couple of notes here.

  1. execution and lookup_cache although available in the builder, are never used in the parser.

  2. min_should_match is used in the parser but marked as deprecated, and can never be set in the builder.

  3. TermsLookupQueryBuilder is a pure delegate to TermsQueryBuilder, and Queries.termsLookupQuery directly creates a new TermsQueryBuilder.

I think we should only document the change in migrate doc for 2) and 3)

@alexksikes alexksikes force-pushed the feature/query-refactoring-terms-query branch from 0815151 to 671e7c7 Compare August 12, 2015 15:03
@alexksikes
Copy link
Contributor Author

@javanna rebased and addressed comments. We should still figure out how best to mock a handleTermsLookup or a Client in our test. This will also be useful for queries such as MLT. Thanks for the review.

@alexksikes alexksikes force-pushed the feature/query-refactoring-terms-query branch from 671e7c7 to 3651c99 Compare August 13, 2015 10:31
}

Query query;
if (context.isFilter()) { // NO COMMIT: not exactly sure how to handle this case, right now using a filter flag
Copy link
Member

Choose a reason for hiding this comment

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

I think this is ok used this way, @cbuescher do you agree ?

Copy link
Member

Choose a reason for hiding this comment

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

I think this is ok, the isFilter() flag should be set when parent queries that are already using toQuery() produce some inner query in a filter context.

Copy link
Member

Choose a reason for hiding this comment

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

cool then remove the NOCOMMIT here?

/**
* Helper method to return a random field (mapped or unmapped) and a value
*/
protected Tuple<String, Object> getRandomFieldNameAndValue(String... exclude) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here as above, since both methods are related and read similar.

@javanna
Copy link
Member

javanna commented Aug 25, 2015

This is much closer now I did another round of review and left some comments

} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), Matchers.containsString("No value specified for terms query"));
}
}
Copy link
Member

Choose a reason for hiding this comment

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

can we add a test that verifies that if you specify both terms_lookup and values on the REST layer we get back a validation error? This part in the parser seems a bit tricky, I want to make sure we don't lose this.

@alexksikes alexksikes force-pushed the feature/query-refactoring-terms-query branch from b92d0c3 to 9b8eef6 Compare August 25, 2015 16:10
@alexksikes
Copy link
Contributor Author

@javanna I addressed all the comments. Hopefully it should be good to go. Thank you for the review.

public TermsQueryBuilder(String name, Iterable values) {
this.name = name;
this.values = values;
public TermsQueryBuilder(String fieldName, Iterable values) {
Copy link
Member

Choose a reason for hiding this comment

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

Iterable<Object>

@javanna
Copy link
Member

javanna commented Aug 26, 2015

I did a last review round, left some minor comments. LGTM otherwise

@@ -56,21 +63,118 @@ public String getId() {
return id;
}

public String getPath() {
Copy link
Member

Choose a reason for hiding this comment

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

last super small comment, can we remove the get prefix from these setters from now, for consistency reasons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to but it would break bwc. Mark them as deprecated?

Copy link
Member

Choose a reason for hiding this comment

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

it doesn't break anything given that this class was only used internally, it was not part of the java api. Only this change makes it part of the java api.

@javanna
Copy link
Member

javanna commented Aug 26, 2015

left one tiny comment, LGTM though

Refactors TermsQueryBuilder and Parser for elastic#10217.

This PR is against the query-refactoring branch.

Closes elastic#12042
@alexksikes alexksikes force-pushed the feature/query-refactoring-terms-query branch from 7f3d530 to 1af0a39 Compare August 26, 2015 11:59
@alexksikes alexksikes merged commit 1af0a39 into elastic:feature/query-refactoring Aug 26, 2015
@alexksikes alexksikes deleted the feature/query-refactoring-terms-query branch August 26, 2015 12:02
@javanna javanna removed the review label Aug 26, 2015
@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Query Refactoring labels Feb 14, 2018
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