Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/105298.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 105298
summary: Ignore duplicate `FieldAliasMappers`
area: TSDB
type: bug

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a bug in unreleased code, let's mark it as non-issue and then a changelog isn't needed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ protected static void parseProperties(
throw new MapperParsingException("No handler for type [" + type + "] declared on field [" + fieldName + "]");
}
Mapper.Builder fieldBuilder;
if (objBuilder.subobjects.value() == false || type.equals(FieldAliasMapper.CONTENT_TYPE)) {
if (objBuilder.subobjects.value() == false) {
fieldBuilder = typeParser.parse(fieldName, propNode, parserContext);
} else {
String[] fieldNameParts = fieldName.split("\\.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,34 @@ void getAliasMappers(Map<String, Mapper> mappers, Map<String, Mapper> aliasMappe
);
}
} else {
FieldAliasMapper aliasMapper = new FieldAliasMapper.Builder(fieldMapper.simpleName()).path(
fieldMapper.mappedFieldType.name()
).build(context);
aliasMappers.put(aliasMapper.simpleName(), aliasMapper);
// Check if the field name contains dots, as aliases require nesting within objects in this case.
String[] fieldNameParts = fieldMapper.simpleName().split("\\.");
if (fieldNameParts.length == 0) {
throw new IllegalArgumentException("field name cannot contain only dots");
}
if (fieldNameParts.length == 1) {
// No nesting required, add the alias directly to the root.
FieldAliasMapper aliasMapper = new FieldAliasMapper.Builder(fieldMapper.simpleName()).path(
fieldMapper.mappedFieldType.name()
).build(context);
aliasMappers.put(aliasMapper.simpleName(), aliasMapper);
} else {
// Nest the alias within object(s).
String realFieldName = fieldNameParts[fieldNameParts.length - 1];
Mapper.Builder fieldBuilder = new FieldAliasMapper.Builder(realFieldName).path(
fieldMapper.mappedFieldType.name()
);
for (int i = fieldNameParts.length - 2; i >= 0; --i) {
String intermediateObjectName = fieldNameParts[i];
ObjectMapper.Builder intermediate = new ObjectMapper.Builder(
intermediateObjectName,
ObjectMapper.Defaults.SUBOBJECTS
);
intermediate.add(fieldBuilder);
fieldBuilder = intermediate;
}
aliasMappers.put(fieldNameParts[0], fieldBuilder.build(context));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public void testPassThroughObjectNested() throws IOException {
}));
assertThat(mapperService.mappingLookup().getMapper("dim"), instanceOf(FieldAliasMapper.class));
assertThat(mapperService.mappingLookup().getMapper("resource.attributes.dim"), instanceOf(KeywordFieldMapper.class));
assertThat(mapperService.mappingLookup().getMapper("another.dim"), instanceOf(FieldAliasMapper.class));
assertThat(mapperService.mappingLookup().objectMappers().get("another").getMapper("dim"), instanceOf(FieldAliasMapper.class));
assertThat(mapperService.mappingLookup().getMapper("attributes.another.dim"), instanceOf(KeywordFieldMapper.class));
}

Expand Down