-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Simplify MergeResult#buildMergedMappers
#104578
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -533,15 +533,19 @@ private static Map<String, Mapper> buildMergedMappers( | |
| MergeReason reason, | ||
| MapperMergeContext objectMergeContext | ||
| ) { | ||
| Map<String, Mapper> mergedMappers = null; | ||
| for (Mapper mergeWithMapper : mergeWith) { | ||
| Mapper mergeIntoMapper = (mergedMappers == null ? existing.mappers : mergedMappers).get(mergeWithMapper.simpleName()); | ||
| Iterator<Mapper> iterator = mergeWith.iterator(); | ||
| if (iterator.hasNext() == false) { | ||
| return Map.copyOf(existing.mappers); | ||
| } | ||
| Map<String, Mapper> mergedMappers = new HashMap<>(existing.mappers); | ||
| while (iterator.hasNext()) { | ||
| Mapper mergeWithMapper = iterator.next(); | ||
| Mapper mergeIntoMapper = mergedMappers.get(mergeWithMapper.simpleName()); | ||
|
|
||
| Mapper merged; | ||
| if (mergeIntoMapper == null) { | ||
| merged = mergeWithMapper; | ||
| mergedMappers.put(mergeWithMapper.simpleName(), mergeWithMapper); | ||
| } else if (mergeIntoMapper instanceof ObjectMapper objectMapper) { | ||
| merged = objectMapper.merge(mergeWithMapper, reason, objectMergeContext); | ||
| mergedMappers.put(objectMapper.simpleName(), objectMapper.merge(mergeWithMapper, reason, objectMergeContext)); | ||
| } else { | ||
| assert mergeIntoMapper instanceof FieldMapper || mergeIntoMapper instanceof FieldAliasMapper; | ||
| if (mergeWithMapper instanceof NestedObjectMapper) { | ||
|
|
@@ -553,22 +557,13 @@ private static Map<String, Mapper> buildMergedMappers( | |
| // If we're merging template mappings when creating an index, then a field definition always | ||
| // replaces an existing one. | ||
| if (reason == MergeReason.INDEX_TEMPLATE) { | ||
| merged = mergeWithMapper; | ||
| mergedMappers.put(mergeWithMapper.simpleName(), mergeWithMapper); | ||
| } else { | ||
| merged = mergeIntoMapper.merge(mergeWithMapper, objectMergeContext); | ||
| mergedMappers.put(mergeWithMapper.simpleName(), mergeIntoMapper.merge(mergeWithMapper, objectMergeContext)); | ||
| } | ||
| } | ||
| if (mergedMappers == null) { | ||
| mergedMappers = new HashMap<>(existing.mappers); | ||
| } | ||
| mergedMappers.put(merged.simpleName(), merged); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can do that. See also #102936 (comment) It's important to decrement the field budget before calling merge on the sub fields. I think we should have the put calls as close as possible to the place where we decrement the field budget.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the latest changes in #102936, that no longer touches these lines, I still don't follow :) The put is still within the loop, even if after the conditional instead of within the conditional . The only merge call I see in this method is performed within the conditional, before the put (before and after your change). What am I missing that makes this part of the changes necessary?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've actually reverted this in #102936 now (see c1b4258). Now that I've removed the What's still important though is that we decrement the budget for the shallow object mapper in |
||
| } | ||
| if (mergedMappers != null) { | ||
| mergedMappers = Map.copyOf(mergedMappers); | ||
| } else { | ||
| mergedMappers = Map.copyOf(existing.mappers); | ||
| } | ||
| return mergedMappers; | ||
| return Map.copyOf(mergedMappers); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.