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

Remove Mapper.updateFieldType() #56986

Merged
merged 9 commits into from
May 26, 2020

Conversation

romseygeek
Copy link
Contributor

When we had multiple mapping types, an update to a field in one type had to be
propagated to the same field in all other types. This was done using the
Mapper.updateFieldType() method, called at the end of a merge. However, now
that we only have a single type per index, this method is unnecessary and can
be removed.

Relates to #41059

@romseygeek romseygeek added :Search Foundations/Mapping Index mappings, including merging and defining field types >breaking-java >refactoring v8.0.0 v7.9.0 labels May 20, 2020
@romseygeek romseygeek self-assigned this May 20, 2020
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Search Meta label for search team label May 20, 2020
@@ -85,7 +85,8 @@
public static ParentJoinFieldMapper getMapper(MapperService service) {
MetaJoinFieldMapper.MetaJoinFieldType fieldType =
(MetaJoinFieldMapper.MetaJoinFieldType) service.fieldType(MetaJoinFieldMapper.NAME);
return fieldType == null ? null : fieldType.getMapper();
return fieldType == null ? null :
(ParentJoinFieldMapper) service.fieldMapper(fieldType.getJoinField());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ParentJoinFieldMapper was using updateFieldType() to update its linked MetaJoinFieldMapper. This requires a small bit of hackery to get round, which I hope to fix in a followup by moving the various filter factory methods from the field mapper to the field type.

@@ -590,6 +584,10 @@ public MappedFieldType fieldType(String fullName) {
return fieldTypes.get(fullName);
}

public Mapper fieldMapper(String fieldName) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is unfortunately necessary as a shim to get round the ParentJoinFieldMapper issue above. Hopefully removed asap.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we avoid adding this new method and call this inline in ParentJoinFieldMapper? All the methods like documentMapper() are public, so it seems do-able.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++ have reworked the mocking (which sent me down a surprisingly deep rabbit hole, but I think it's fixed now!)

@@ -439,7 +431,9 @@ private boolean assertMappersShareSameFieldType() {
Collections.addAll(fieldMappers, mapper.mapping().metadataMappers);
MapperUtils.collect(mapper.root(), new ArrayList<>(), fieldMappers, new ArrayList<>());
for (FieldMapper fieldMapper : fieldMappers) {
assert fieldMapper.fieldType() == fieldTypes.get(fieldMapper.name()) : fieldMapper.name();
assert Objects.equals(fieldMapper.fieldType(), fieldTypes.get(fieldMapper.name())) :
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could remove this whole method assertMappersShareSameFieldType, it doesn't seem helpful now that we only have one type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++

@@ -812,10 +812,6 @@ private static void parseDynamicValue(final ParseContext context, ObjectMapper p
builder = createBuilderFromDynamicValue(context, token, currentFieldName);
}
Mapper mapper = builder.build(builderContext);
if (existingFieldType != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm understanding correctly, we can now assume existingFieldType will always be null, since there is only one type. In that case we could remove the logic above too, including the method createBuilderFromFieldType.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++

@@ -590,6 +584,10 @@ public MappedFieldType fieldType(String fullName) {
return fieldTypes.get(fullName);
}

public Mapper fieldMapper(String fieldName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we avoid adding this new method and call this inline in ParentJoinFieldMapper? All the methods like documentMapper() are public, so it seems do-able.

DocumentMapper mapper = mock(DocumentMapper.class);
when(mapper.typeText()).thenReturn(new Text(TYPE_NAME));
when(mapper.type()).thenReturn(TYPE_NAME);
when(mapperService.documentMapper()).thenReturn(mapper);
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 wasted several hours trying to work out why my mocked DocumentMapper class wasn't returning the DocumentFieldMapper instance I was asking it to. This appears to be unnecessary, so I've removed it

Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

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

Looks good to me!

} else {
builder = createBuilderFromDynamicValue(context, token, currentFieldName);
}
final Mapper.Builder<?> builder = createBuilderFromDynamicValue(context, token, currentFieldName);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can delete createBuilderFromFieldType now, since it's unused.

@romseygeek romseygeek merged commit fed71fb into elastic:master May 26, 2020
@romseygeek
Copy link
Contributor Author

The backport on this is a bit complicated due to default types still being present (but unused!) in 7x, so I will open a separate PR.

romseygeek added a commit to romseygeek/elasticsearch that referenced this pull request May 26, 2020
When we had multiple mapping types, an update to a field in one type had to be
propagated to the same field in all other types. This was done using the
Mapper.updateFieldType() method, called at the end of a merge. However, now
that we only have a single type per index, this method is unnecessary and can
be removed.

Relates to elastic#41059
romseygeek added a commit that referenced this pull request May 27, 2020
When we had multiple mapping types, an update to a field in one type had to be
propagated to the same field in all other types. This was done using the
Mapper.updateFieldType() method, called at the end of a merge. However, now
that we only have a single type per index, this method is unnecessary and can
be removed.

Relates to #41059
Backport of #56986
@jakelandis jakelandis removed the v8.0.0 label Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>breaking-java >refactoring :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v7.9.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants