Added a Builder for KeywordFieldType, removed redundant constructors#136846
Closed
Kubik42 wants to merge 1 commit intoelastic:mainfrom
Closed
Added a Builder for KeywordFieldType, removed redundant constructors#136846Kubik42 wants to merge 1 commit intoelastic:mainfrom
Kubik42 wants to merge 1 commit intoelastic:mainfrom
Conversation
88c816b to
735cc1e
Compare
735cc1e to
7b63293
Compare
Collaborator
|
Pinging @elastic/es-storage-engine (Team:StorageEngine) |
jordan-powers
approved these changes
Oct 21, 2025
Contributor
jordan-powers
left a comment
There was a problem hiding this comment.
LGTM, thanks Dmitry!
martijnvg
reviewed
Oct 22, 2025
Member
martijnvg
left a comment
There was a problem hiding this comment.
This adds more production code than it removes and top of that there is another builder but now just for keyword field type.
I think the right change here is to remove the number of constructors here. Looks like 3 out of 5 constructors are exclusively used in tests. Let's try to reduce the number of constructors to just one or two. At best the rest of the constructors can be factory methods in testing code, or just removed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a follow up for #132962, where one of the feedbacks I got was to clean up
KeywordFieldType's constructors.I agree with this feedback. The constructors are very long and nearly identical. This makes them quite error prone and difficult to extend.
This PR addresses that by removing all but one constructor and replacing them with a
Builder.Note, I left behind one of the constructors as it was too messy to remove. The two classes that rely on it (ValuesSourceReaderBenchmark and EsPhysicalOperationProviders) can be reworked, but the end result is quite messy. Frankly, this mess is a consequence of how we're using the constructor in the first place. That being, we're creating a "builder" and bypassing the actual building in favor of using the builder as a data carrier, and then overriding a bunch of things that builder would've done for us. The workaround is to actually call
builder.build(), but there are so nuances with needing to create aMapperBuilderContextfor the builder to use, which I don't think is a good idea given that this is production and non-test code.