Skip to content
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

Merged
merged 6 commits into from
Jun 16, 2021

Conversation

romseygeek
Copy link
Contributor

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.

@romseygeek romseygeek self-assigned this Jun 7, 2021
@romseygeek romseygeek requested a review from javanna June 7, 2021 13:55
@romseygeek romseygeek added :Search Foundations/Mapping Index mappings, including merging and defining field types >refactoring v7.14.0 v8.0.0 labels Jun 7, 2021
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jun 7, 2021
@elasticmachine
Copy link
Collaborator

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

Copy link
Member

@javanna javanna left a 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}.
Copy link
Member

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");
}
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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?

Copy link
Member

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

Copy link
Contributor Author

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"));
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

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?

Copy link
Member

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();
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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");
}
Copy link
Member

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?

@romseygeek
Copy link
Contributor Author

@elasticmachine update branch

@romseygeek romseygeek force-pushed the runtime/standalone-parser branch from 9f765f0 to b22257e Compare June 16, 2021 08:25
@romseygeek romseygeek merged commit a18b1cc into elastic:master Jun 16, 2021
@romseygeek romseygeek deleted the runtime/standalone-parser branch June 16, 2021 09:34
romseygeek added a commit that referenced this pull request Jun 16, 2021
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.
limingnihao pushed a commit to limingnihao/elasticsearch that referenced this pull request Jun 17, 2021
* 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)
  ...
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.14.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants