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

QueryBuilder does not need generics. #18133

Merged
merged 1 commit into from
May 6, 2016

Conversation

jpountz
Copy link
Contributor

@jpountz jpountz commented May 4, 2016

QueryBuilder has generics, but those are never used: all call sites use
QueryBuilder<?>. Only AbstractQueryBuilder needs generics so that the base
class can contain a default implementation for setters that returns this.

@@ -50,7 +50,7 @@
/**
* Sets the arbitrary name to be assigned to the query (see named queries).
*/
QB queryName(String queryName);
QueryBuilder queryName(String queryName);
Copy link
Member

Choose a reason for hiding this comment

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

This is why it had the generics. OTOH I'll bet if we always return the subclass of QueryBuilder anyplace interesting and have each of them implement this method by returning their own type then no client code will have to change. We should probably add something to the docs on this method telling implementers to return their own type, not QueryBuilder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works fine in practice because query builders are always constructed with their concrete type. With this pull request already, none of the client code that we had in the test folders had to change.

I will add the note to the javadocs of QueryBuilder (pointing out that extending AbstractQueryBuilder does it for you).

Copy link
Member

Choose a reason for hiding this comment

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

extending AbstractQueryBuilder does it for you

Awesome!

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 just pushed one more commit with docs.

@nik9000
Copy link
Member

nik9000 commented May 4, 2016

I felt a great disturbance in the Force, as if hundreds of spurious warnings suddenly cried out in terror, and were suddenly silenced. I fear something awesome has happened.

@nik9000
Copy link
Member

nik9000 commented May 4, 2016

LGTM

QueryBuilder has generics, but those are never used: all call sites use
`QueryBuilder<?>`. Only `AbstractQueryBuilder` needs generics so that the base
class can contain a default implementation for setters that returns `this`.
@jpountz jpountz force-pushed the fix/querybuilder_generics branch from 35ab316 to 7d87087 Compare May 6, 2016 07:12
@jpountz jpountz merged commit 7d87087 into elastic:master May 6, 2016
jpountz added a commit to jpountz/elasticsearch that referenced this pull request Jun 1, 2016
…lastic#18368

Similar reasoning as elastic#18133 but for the aggs API. One important change is that
I moved the base PipelineAggregatorBuilder class to the o.e.s.aggregations
package instead of o.e.s.aggregations.pipeline so that the create method does
not need to be public.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants