-
Notifications
You must be signed in to change notification settings - Fork 25k
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
RuntimeField.Builder should not extend FieldMapper.Builder #73840
RuntimeField.Builder should not extend FieldMapper.Builder #73840
Conversation
Pinging @elastic/es-search (Team:Search) |
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.
left a couple of initial comments, thanks for working on this!
@@ -58,49 +63,70 @@ default XContentBuilder toXContent(XContentBuilder builder, Params params) throw | |||
|
|||
/** | |||
* For runtime fields the {@link RuntimeField.Parser} returns directly the {@link MappedFieldType}. |
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 also a lie at this point :)
if (propNode == null && parameter.canAcceptNull() == false) { | ||
throw new MapperParsingException("[" + propName + "] on mapper [" + name | ||
+ "] of type [" + type + "] must not have a [null] 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.
I wonder if it's worth factoring out this code that is common between the two implementations instead of duplicating it, though it would mean that the base class has to allow to be extended to introduce parsing of common fields 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.
I think the two methods are sufficiently different that it's not worth trying to share stuff here.
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.
are they? I did not realize that
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 have not deprecated anything on the runtime section so far, but I do wonder: should we handle deprecations like we do for field mappers?
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 guess this makes sense only if we share the code between the two, supporting parameters deprecation while there isn't one deprecated parameter is overkill
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 can copy the machinery from FieldMapper easily enough if we need to
@@ -115,7 +116,7 @@ public void testMultiFieldsIsNotSupported() throws IOException { | |||
b.startObject("fields").startObject("test").field("type", "keyword").endObject().endObject(); | |||
}); | |||
MapperParsingException exception = expectThrows(MapperParsingException.class, () -> createMapperService(mapping)); | |||
assertEquals("Failed to parse mapping: runtime field [field] does not support [fields]", exception.getMessage()); | |||
assertThat(exception.getMessage(), containsString("unknown parameter [fields] on mapper")); |
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.
if we do duplicate the code, I wonder if the message could be tailored to runtime fields, like it used to be. If we decide not to duplicate the code , I guess there is no way around it. In general, I am surprised that we call this "mapper": do users even know what a mapper is?
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've replaced this error message to refer to runtime field
instead of mapper
|
||
@Override | ||
public final FieldMapper build(ContentPath context) { | ||
throw new UnsupportedOperationException(); | ||
public final XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { |
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've been wondering why the builder is only responsible to print out its parameters. Could we include RuntimeField#toXContent in this so that we don't need to wrap it? If we do so maybe the toXContent within AbstractScriptFieldType could take a RUntimeField.Builder argument instead of ToXCOntent?
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.
let's see if we can do this as a follow-up, not important for merging
propName, | ||
type | ||
); | ||
iterator.remove(); |
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.
does this deserve a new test that targets runtime fields specifically?
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've been writing tests for this and I think I've found a bug with the existing impl - we're supposed to issue a deprecation warning if dynamic templates contain mappings with bad parameters, but we actually throw an error because the template validation doesn't propagate its 'within a dynamic template' context. Will open a separate PR for it.
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.
sounds good
if (propNode == null && parameter.canAcceptNull() == false) { | ||
throw new MapperParsingException("[" + propName + "] on mapper [" + name | ||
+ "] of type [" + type + "] must not have a [null] 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.
We have not deprecated anything on the runtime section so far, but I do wonder: should we handle deprecations like we do for field mappers?
@elasticmachine update branch |
9f765f0
to
b22257e
Compare
RuntimeField.Builder currently extends FieldMapper.Builder so that it can share some parsing code and re-use the Parameter infrastructure. However, this also means that we have to have a number of no-op method implementations, and in addition this will make it complicated to add a fields parameter within multi-keyed object field types. This commit removes the class relationship between these two classes.
* master: (284 commits) [DOCS] Update central reporting image (elastic#74195) [DOCS] SQL: Document `null` handing for string functions (elastic#74201) Fix Snapshot Docs Listing Query Params in Body Incorrectly (elastic#74196) [DOCS] EQL: Note EQL uses `fields` parameter (elastic#74194) Mute failing MixedClusterClientYamlTestSuiteIT test {p0=indices.split/20_source_mapping/Split index ignores target template mapping} test (elastic#74198) Cleanup Duplicate Constants in Snapshot XContent Params (elastic#74114) [DOC] Add watcher to the threadpool doc (elastic#73935) [Rest Api Compatibility] Validate Query typed api (elastic#74171) Replace deprecated `script.cache.*` settings with `script.context.$constext.cache_*` in documentation. (elastic#74144) Pin Alpine Linux version in Docker builds (elastic#74169) Fix clone API settings docs bug (elastic#74175) [ML] refactor internal datafeed management (elastic#74018) Disable query cache for FunctionScoreQuery and ScriptScoreQuery (elastic#74060) Fork the sending of file chunks during recovery (elastic#74164) RuntimeField.Builder should not extend FieldMapper.Builder (elastic#73840) Run CheckIndex on metadata index before loading (elastic#73239) Deprecate setting version on analyzers (elastic#74073) Add test with null transform id in stats request (elastic#74130) Order imports when reformatting (elastic#74059) Move deprecation code from xpack core to deprecation module. (elastic#74120) ...
RuntimeField.Builder currently extends FieldMapper.Builder so that it can
share some parsing code and re-use the Parameter infrastructure. However,
this also means that we have to have a number of no-op method implementations,
and in addition this will make it complicated to add a
fields
parameter withinmulti-keyed object field types. This commit removes the class relationship
between these two classes.