-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Allow plugins outside core package to access and override some function of FieldMapper #17575
Open
bzhangam
wants to merge
1
commit into
opensearch-project:main
Choose a base branch
from
bzhangam:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change relax the access to this function but all its subclasses override it with protected access modifier and we also need to change them as public. I have updated all subclasses in core. But if there is any plugin extending it we also need to update the plugin accordingly. Not sure how should we communicate change like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me why these need to be changed from
protected
topublic
.Subclasses can still override
protected
methods, even it they're defined in a plugin.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to make it public to allow plugin to invoke it through a field type not override it. Since we want to delegate the query work to the delegate field type and in plugin we cannot invoke the protected function even we are in the subclass. Check this code change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it -- I think you would need
SemanticFieldMapper
to extendTermBasedFieldMapper
in order to have access to theprotected
method. I wonder if that would make sense? It does look like you want yourSemanticFieldMapper
to have term-based behavior, but be decoupled from the specifics of which term-based field type is being wrapped.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean TermBasedFieldType? We are extending the StringFieldType which extends the TermBasedFieldType. It can access the protected method in core package. But in neural plugin we cannot access it we only can override it. But we want to delegate the query work to the wrapped field type where we don't want to override the function but invoke the function of the wrapped field type directly. To do that we need to make it publish like other functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mainly needed by KeywordFieldMapper since it overrides the default behavior of the indexedValueForSearch function. Otherwise we don't need to override it since when we are extending the StringFieldType which has a default implementation for this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right -- but
indexedValueForSearch
only needs to be implemented so that it can be called from the various*Query
methods, which are declared inMappedFieldType
.If
SemanticStringFieldType
extendsMappedFieldType
, it can delegate all of the*Query
methods todelegate
without caring about the internal implementation details (indexedValueForSearch
). Would that work?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't care about the internal implementation details we just want to delegate the work. To delegate the work we need to do something like:
We cannot simply rely on our semantic field type even it's already extending the string field type because it's possible the delegate field type can have new parameters. e.g. code. And it can make the semantic field type behave different from the delegate field type.
The way we can avoid this I think is to extend the delegate field type directly. e.g. If we have a semanticKeywordFieldType extending the KeywordFieldType and use the delegate keyword field type to set the same parameters for it then we don't need to override the function to delegate the query work. We can directly use it since it should behave the same as the delegate keyword field type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but if
SemanticStringFieldType
extendsMappedFieldType
, then it doesn't need to delegateindexedValueForSearch
, because it doesn't care that it exists (it's not part of the signature ofMappedFieldType
).The fact that the
delegate
field type internally has anindexedValueForSearch
is hidden by the delegated calls totermQuery
, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synced offline with Michael. We will create a FilterFieldType in core to handle the delegate work and in plugin we simply need to extend it. This PR will not be needed.