Simplify the return type of FieldMapper#parse. (#32654)

This commit is contained in:
Julie Tibshirani 2018-09-04 01:15:19 +00:00 committed by GitHub
parent 767d8e0801
commit 78df00ff24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 21 additions and 42 deletions

View File

@ -135,7 +135,7 @@ public class FeatureVectorFieldMapper extends FieldMapper {
}
@Override
public FieldMapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
if (context.externalValueSet()) {
throw new IllegalArgumentException("[feature_vector] fields can't be used in multi-fields");
}
@ -164,7 +164,6 @@ public class FeatureVectorFieldMapper extends FieldMapper {
"float, but got unexpected token " + token);
}
}
return null; // no mapping update
}
@Override

View File

@ -375,7 +375,7 @@ public final class ParentJoinFieldMapper extends FieldMapper {
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
context.path().add(simpleName());
XContentParser.Token token = context.parser().currentToken();
String name = null;
@ -437,7 +437,6 @@ public final class ParentJoinFieldMapper extends FieldMapper {
context.doc().add(field);
context.doc().add(new SortedDocValuesField(fieldType().name(), binaryValue));
context.path().remove();
return null;
}
@Override

View File

@ -383,7 +383,7 @@ public class PercolatorFieldMapper extends FieldMapper {
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
QueryShardContext queryShardContext = this.queryShardContext.get();
if (context.doc().getField(queryBuilderField.name()) != null) {
// If a percolator query has been defined in an array object then multiple percolator queries
@ -406,7 +406,6 @@ public class PercolatorFieldMapper extends FieldMapper {
createQueryBuilderField(indexVersion, queryBuilderField, queryBuilder, context);
Query query = toQuery(queryShardContext, isMapUnmappedFieldAsText(), queryBuilder);
processQuery(query, context);
return null;
}
static void createQueryBuilderField(Version indexVersion, BinaryFieldMapper qbField,

View File

@ -145,9 +145,8 @@ public class SizeFieldMapper extends MetadataFieldMapper {
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
// nothing to do here, we call the parent in postParse
return null;
}
@Override

View File

@ -430,7 +430,7 @@ public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapp
* else adds inputs as a {@link org.apache.lucene.search.suggest.document.SuggestField}
*/
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
// parse
XContentParser parser = context.parser();
Token token = parser.currentToken();
@ -438,7 +438,7 @@ public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapp
// ignore null values
if (token == Token.VALUE_NULL) {
return null;
return;
} else if (token == Token.START_ARRAY) {
while ((token = parser.nextToken()) != Token.END_ARRAY) {
parse(context, token, parser, inputMap);
@ -477,7 +477,6 @@ public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapp
context.doc().add(field);
}
multiFields.parse(this, context);
return null;
}
/**

View File

@ -462,10 +462,7 @@ final class DocumentParser {
parseObjectOrNested(context, (ObjectMapper) mapper);
} else if (mapper instanceof FieldMapper) {
FieldMapper fieldMapper = (FieldMapper) mapper;
Mapper update = fieldMapper.parse(context);
if (update != null) {
context.addDynamicMapper(update);
}
fieldMapper.parse(context);
parseCopyFields(context, fieldMapper.copyTo().copyToFields());
} else if (mapper instanceof FieldAliasMapper) {
throw new IllegalArgumentException("Cannot write to a field alias [" + mapper.name() + "].");

View File

@ -264,11 +264,9 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
}
/**
* Parse using the provided {@link ParseContext} and return a mapping
* update if dynamic mappings modified the mappings, or {@code null} if
* mappings were not modified.
* Parse the field value using the provided {@link ParseContext}.
*/
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
final List<IndexableField> fields = new ArrayList<>(2);
try {
parseCreateField(context, fields);
@ -280,7 +278,6 @@ public abstract class FieldMapper extends Mapper implements Cloneable {
fieldType().typeName());
}
multiFields.parse(this, context);
return null;
}
/**

View File

@ -215,9 +215,8 @@ public class FieldNamesFieldMapper extends MetadataFieldMapper {
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
// Adding values to the _field_names field is handled by the mappers for each field type
return null;
}
static Iterable<String> extractFieldNames(final String fullPath) {

View File

@ -284,7 +284,7 @@ public class GeoPointFieldMapper extends FieldMapper implements ArrayValueMapper
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
context.path().add(simpleName());
GeoPoint sparse = context.parseExternalValue(GeoPoint.class);
@ -339,7 +339,6 @@ public class GeoPointFieldMapper extends FieldMapper implements ArrayValueMapper
}
context.path().remove();
return null;
}
/**

View File

@ -483,13 +483,13 @@ public class GeoShapeFieldMapper extends FieldMapper {
return (GeoShapeFieldType) super.fieldType();
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
try {
Shape shape = context.parseExternalValue(Shape.class);
if (shape == null) {
ShapeBuilder shapeBuilder = ShapeParser.parse(context.parser(), this);
if (shapeBuilder == null) {
return null;
return;
}
shape = shapeBuilder.build();
}
@ -501,7 +501,7 @@ public class GeoShapeFieldMapper extends FieldMapper {
for (Shape s : shapes) {
indexShape(context, s);
}
return null;
return;
} else if (shape instanceof Point == false) {
throw new MapperParsingException("[{" + fieldType().name() + "}] is configured for points only but a " +
((shape instanceof JtsGeometry) ? ((JtsGeometry)shape).getGeom().getGeometryType() : shape.getClass()) + " was found");
@ -515,7 +515,6 @@ public class GeoShapeFieldMapper extends FieldMapper {
}
context.addIgnoredField(fieldType.name());
}
return null;
}
private void indexShape(ParseContext context, Shape shape) {

View File

@ -129,9 +129,8 @@ public final class IgnoredFieldMapper extends MetadataFieldMapper {
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
// done in post-parse
return null;
}
@Override

View File

@ -158,11 +158,10 @@ public class RoutingFieldMapper extends MetadataFieldMapper {
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
// no need ot parse here, we either get the routing in the sourceToParse
// or we don't have routing, if we get it in sourceToParse, we process it in preParse
// which will always be called
return null;
}
@Override

View File

@ -242,9 +242,8 @@ public class SeqNoFieldMapper extends MetadataFieldMapper {
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
// fields are added in parseCreateField
return null;
}
@Override

View File

@ -219,9 +219,8 @@ public class SourceFieldMapper extends MetadataFieldMapper {
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
// nothing to do here, we will call it in pre parse
return null;
}
@Override

View File

@ -287,9 +287,8 @@ public class TypeFieldMapper extends MetadataFieldMapper {
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
// we parse in pre parse
return null;
}
@Override

View File

@ -117,9 +117,8 @@ public class VersionFieldMapper extends MetadataFieldMapper {
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
// _version added in preparse
return null;
}
@Override

View File

@ -168,7 +168,7 @@ public class ExternalMapper extends FieldMapper {
}
@Override
public Mapper parse(ParseContext context) throws IOException {
public void parse(ParseContext context) throws IOException {
byte[] bytes = "Hello world".getBytes(Charset.defaultCharset());
binMapper.parse(context.createExternalValueContext(bytes));
@ -190,7 +190,6 @@ public class ExternalMapper extends FieldMapper {
stringMapper.parse(context);
multiFields.parse(this, context);
return null;
}
@Override