Skip to content

Simplify adding dynamic sub-fields to their dynamic parent object#87866

Merged
javanna merged 2 commits intoelastic:masterfrom
javanna:refactoring/dynamic_object_builder
Jun 21, 2022
Merged

Simplify adding dynamic sub-fields to their dynamic parent object#87866
javanna merged 2 commits intoelastic:masterfrom
javanna:refactoring/dynamic_object_builder

Conversation

@javanna
Copy link
Copy Markdown
Contributor

@javanna javanna commented Jun 20, 2022

DocumentParserContext holds all the dynamic mappers created while parsing a document, as well as dynamic object mappers on a separate map so they can be looked up by name quickly when parsing their sub-fields and looking for their parent field. For every sub-field, so far we looked up the corresponding object mapper and then call .newBuilder on it. Calling newBuilder can be done already when the object mapper is added to the map, which simplifies the logic down the line as instead of creating a new builde for each sub-field, we re-use the same builder and add sub-fields to it. This has no effect on the resulting dynamic update, but it simplifies the code and it should have a positive impact on performance.

DocumentParserContext holds all the dynamic mappers created while parsing a document, as well as dynamic object mappers on a separate map so they can be looked up by name quickly when parsing their sub-fields and looking for their parent field. For every sub-field, so far we looked up the corresponding object mapper and then call .newBuilder on it. Calling newBuilder can be done already when the object mapper is added to the map, which simplifies the logic down the line as instead of creating a new builde for each sub-field, we re-use the same builder and add sub-fields to it. This has no effect on the resulting dynamic update, but it simplifies the code and it should have a positive impact on performance.
@javanna javanna added the :Search Foundations/Mapping Index mappings, including merging and defining field types label Jun 21, 2022
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jun 21, 2022
@javanna javanna added >refactoring and removed Team:Search Meta label for search team labels Jun 21, 2022
@elasticmachine
Copy link
Copy Markdown
Collaborator

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

@javanna javanna requested a review from romseygeek June 21, 2022 14:33
Copy link
Copy Markdown
Contributor

@romseygeek romseygeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

One question, does this mean that we can get rid of the object merging when we build the final dynamic update now? Because we should only have a single builder per object, right?

if (parentMapper == null) {
ObjectMapper.Builder dynamicObjectMapperBuilder = context.getDynamicObjectMapperBuilder(parentName);
if (dynamicObjectMapperBuilder == null) {
// it can still happen that the path is ambiguous and we are not able to locate the parent
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is still true? I guess it doesn't matter so much.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are very much aligned :) I want to to do something about this in a follow-up. I think probably have an assertion that this never happens. If it does happen I would like to know why...

@javanna
Copy link
Copy Markdown
Contributor Author

javanna commented Jun 21, 2022

One question, does this mean that we can get rid of the object merging when we build the final dynamic update now? Because we should only have a single builder per object, right?

Not yet, but that would be the plan more or less... I haven't figured out exactly how to get there but I am on it.

@javanna javanna merged commit 73b0273 into elastic:master Jun 21, 2022
javanna added a commit that referenced this pull request Jun 21, 2022
…ject (#87866)"

This reverts commit 73b0273 (#87866) as an unexpected percolator test failure has surfaced, which did not surface as part of the PR tests run.
@javanna javanna removed the v8.4.0 label Jun 21, 2022
@javanna
Copy link
Copy Markdown
Contributor Author

javanna commented Jun 30, 2022

Heads, up this was reverted due to a considerable performance regression when building the root object mapper as part of creating the dynamic mapping update. I will dig to understand what caused that and eventually reopen.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants