-
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
base: main
Are you sure you want to change the base?
Conversation
@@ -69,7 +69,7 @@ public TermBasedFieldType( | |||
/** Returns the indexed value used to construct search "values". | |||
* This method is used for the default implementations of most | |||
* query factory methods such as {@link #termQuery}. */ | |||
protected BytesRef indexedValueForSearch(Object value) { | |||
public BytesRef indexedValueForSearch(Object value) { |
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
to public
.
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 extend TermBasedFieldMapper
in order to have access to the protected
method. I wonder if that would make sense? It does look like you want your SemanticFieldMapper
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 in MappedFieldType
.
If SemanticStringFieldType
extends MappedFieldType
, it can delegate all of the *Query
methods to delegate
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:
@Override
public BytesRef indexedValueForSearch(Object value) {
return delegateFieldType.indexedValueForSearch(value);
}
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
extends MappedFieldType
, then it doesn't need to delegate indexedValueForSearch
, because it doesn't care that it exists (it's not part of the signature of MappedFieldType
).
The fact that the delegate
field type internally has an indexedValueForSearch
is hidden by the delegated calls to termQuery
, 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.
❌ Gradle check result for 1cc9d6b: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
…on of FieldMapper Signed-off-by: Bo Zhang <[email protected]>
❕ Gradle check result for e8c8411: UNSTABLE
Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17575 +/- ##
============================================
- Coverage 72.46% 72.36% -0.10%
+ Complexity 65757 65694 -63
============================================
Files 5311 5311
Lines 305001 305013 +12
Branches 44230 44232 +2
============================================
- Hits 221022 220728 -294
- Misses 65932 66217 +285
- Partials 18047 18068 +21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
Allow plugin out side core package to access some functions and fields of the FieldMapper.
Allow plugin to override the merge function of the FieldMapper.
Related Issues
This is needed to support this PR for this feature.
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.