Skip to content

Simplify generics on Mapper.Builder #56747

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

Merged
merged 5 commits into from
May 15, 2020

Conversation

romseygeek
Copy link
Contributor

Mapper.Builder currently has some complex generics on it to allow fluent builder
construction. However, the second parameter, a return type from the build() method,
is unnecessary, as we can use covariant return types. This commit removes this second
generic parameter.

@romseygeek romseygeek added :Search Foundations/Mapping Index mappings, including merging and defining field types >refactoring v8.0.0 v7.9.0 labels May 14, 2020
@romseygeek romseygeek self-assigned this May 14, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Mapping)

@elasticmachine elasticmachine added the Team:Search Meta label for search team label May 14, 2020
@romseygeek
Copy link
Contributor Author

I think we can probably remove the first generic parameter as well, if we're willing to give up on fluent builders - it adds a lot of complexity and visual noise for not much return, IMO.

@romseygeek romseygeek requested a review from jpountz May 14, 2020 09:17
@romseygeek romseygeek requested a review from cbuescher May 14, 2020 10:08
Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

Great simplification, I was looking for the spots where we actually needed that second parameters and could only find one where I'm even not sure (left a short question just for my understanding). LGTM from my side.
I have one question regarding backport to 7.9 though: are we allowing users to define and add custom field types to Elasticsearch, e.g. via Plugins? In this case this might be a breaking change I think. Not sure about this though.

public Builder(String name, MappedFieldType fieldType, MappedFieldType defaultFieldType) {
super(name, fieldType, defaultFieldType);
}

public abstract MetadataFieldMapper build(BuilderContext context);
Copy link
Member

Choose a reason for hiding this comment

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

just out of curiosity: this seems to be one of the few reasons where the generic build return type was needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few places in tests as well that expect build() to return a specific type, but nothing within the server code itself.

@romseygeek
Copy link
Contributor Author

are we allowing users to define and add custom field types to Elasticsearch, e.g. via Plugins?

Yes, this would be a breaking change, but I think we allow these in point releases? That's why plugins have to be tied to a specific release.

I've actually tried removing the first generic parameter as well, and that adds very little noise to the PR but makes things a whole lot simpler still - should I include that here, or open up a followup do you think?

@cbuescher
Copy link
Member

I think we allow these in point releases? That's why plugins have to be tied to a specific release.

Tbh I'm not sure, just wanted to bring this up since it came to mind. Maybe needs another opinion.

I've actually tried removing the first generic parameter as well

I wouldn't mind if its in a separate commit. Depending on the diff it might make sense to open another PR though, also maybe for folks who e.g. later want to track the history of an API change.

@romseygeek
Copy link
Contributor Author

It's mostly changes on the same lines as this current one - I'll push the new changes here.

@romseygeek
Copy link
Contributor Author

Have reverted the complete generics removal, and I'll open a separate issue for that.

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM to the first part

@romseygeek romseygeek merged commit 0cc2345 into elastic:master May 15, 2020
@romseygeek romseygeek deleted the mapper/builder-generics branch May 15, 2020 11:06
romseygeek added a commit that referenced this pull request May 15, 2020
Mapper.Builder currently has some complex generics on it to allow fluent builder
construction. However, the second parameter, a return type from the build() method,
is unnecessary, as we can use covariant return types. This commit removes this second
generic parameter.
romseygeek added a commit that referenced this pull request Oct 13, 2020
We simplified the generics on Mapper.Builder in #56747, but stopped short
of removing them entirely because they were still used in various places in
the code. Now that most field mappers have been converted to parametrized
form, these generics are no longer useful. There are very few places where
a fluent Builder pattern is used, almost all in tests, and these can all be
replaced with simple casts; in exchange, we remove lots of visual cruft and
clean up a number of warnings.
romseygeek added a commit that referenced this pull request Oct 13, 2020
We simplified the generics on Mapper.Builder in #56747, but stopped short
of removing them entirely because they were still used in various places in
the code. Now that most field mappers have been converted to parametrized
form, these generics are no longer useful. There are very few places where
a fluent Builder pattern is used, almost all in tests, and these can all be
replaced with simple casts; in exchange, we remove lots of visual cruft and
clean up a number of warnings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>refactoring :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v7.9.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants