Skip to content

Commit 4da9f18

Browse files
committed
Simplify the return type of FieldMapper#parse. (#32654)
1 parent 3ecb399 commit 4da9f18

File tree

18 files changed

+22
-44
lines changed

18 files changed

+22
-44
lines changed

modules/parent-join/src/main/java/org/elasticsearch/join/mapper/ParentJoinFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ protected void parseCreateField(ParseContext context, List<IndexableField> field
379379
}
380380

381381
@Override
382-
public Mapper parse(ParseContext context) throws IOException {
382+
public void parse(ParseContext context) throws IOException {
383383
context.path().add(simpleName());
384384
XContentParser.Token token = context.parser().currentToken();
385385
String name = null;
@@ -441,7 +441,6 @@ public Mapper parse(ParseContext context) throws IOException {
441441
context.doc().add(field);
442442
context.doc().add(new SortedDocValuesField(fieldType().name(), binaryValue));
443443
context.path().remove();
444-
return null;
445444
}
446445

447446
@Override

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public FieldMapper updateFieldType(Map<String, MappedFieldType> fullNameToFieldT
402402
}
403403

404404
@Override
405-
public Mapper parse(ParseContext context) throws IOException {
405+
public void parse(ParseContext context) throws IOException {
406406
QueryShardContext queryShardContext = this.queryShardContext.get();
407407
if (context.doc().getField(queryBuilderField.name()) != null) {
408408
// If a percolator query has been defined in an array object then multiple percolator queries
@@ -425,7 +425,6 @@ public Mapper parse(ParseContext context) throws IOException {
425425
createQueryBuilderField(indexVersion, queryBuilderField, queryBuilder, context);
426426
Query query = toQuery(queryShardContext, isMapUnmappedFieldAsText(), queryBuilder);
427427
processQuery(query, context);
428-
return null;
429428
}
430429

431430
static void createQueryBuilderField(Version indexVersion, BinaryFieldMapper qbField,

plugins/mapper-size/src/main/java/org/elasticsearch/index/mapper/size/SizeFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ public void postParse(ParseContext context) throws IOException {
149149
}
150150

151151
@Override
152-
public Mapper parse(ParseContext context) throws IOException {
152+
public void parse(ParseContext context) throws IOException {
153153
// nothing to do here, we call the parent in postParse
154-
return null;
155154
}
156155

157156
@Override

server/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,8 @@ public void postParse(ParseContext context) throws IOException {
244244
}
245245

246246
@Override
247-
public Mapper parse(ParseContext context) throws IOException {
247+
public void parse(ParseContext context) throws IOException {
248248
// we parse in post parse
249-
return null;
250249
}
251250

252251
@Override

server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,15 +430,15 @@ public CompletionFieldType fieldType() {
430430
* else adds inputs as a {@link org.apache.lucene.search.suggest.document.SuggestField}
431431
*/
432432
@Override
433-
public Mapper parse(ParseContext context) throws IOException {
433+
public void parse(ParseContext context) throws IOException {
434434
// parse
435435
XContentParser parser = context.parser();
436436
Token token = parser.currentToken();
437437
Map<String, CompletionInputMetaData> inputMap = new HashMap<>(1);
438438

439439
// ignore null values
440440
if (token == Token.VALUE_NULL) {
441-
return null;
441+
return;
442442
} else if (token == Token.START_ARRAY) {
443443
while ((token = parser.nextToken()) != Token.END_ARRAY) {
444444
parse(context, token, parser, inputMap);
@@ -477,7 +477,6 @@ public Mapper parse(ParseContext context) throws IOException {
477477
context.doc().add(field);
478478
}
479479
multiFields.parse(this, context);
480-
return null;
481480
}
482481

483482
/**

server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,7 @@ private static void parseObjectOrField(ParseContext context, Mapper mapper) thro
479479
parseObjectOrNested(context, (ObjectMapper) mapper);
480480
} else if (mapper instanceof FieldMapper) {
481481
FieldMapper fieldMapper = (FieldMapper) mapper;
482-
Mapper update = fieldMapper.parse(context);
483-
if (update != null) {
484-
context.addDynamicMapper(update);
485-
}
482+
fieldMapper.parse(context);
486483
parseCopyFields(context, fieldMapper.copyTo().copyToFields());
487484
} else if (mapper instanceof FieldAliasMapper) {
488485
throw new IllegalArgumentException("Cannot write to a field alias [" + mapper.name() + "].");

server/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,9 @@ public CopyTo copyTo() {
287287
}
288288

289289
/**
290-
* Parse using the provided {@link ParseContext} and return a mapping
291-
* update if dynamic mappings modified the mappings, or {@code null} if
292-
* mappings were not modified.
290+
* Parse the field value using the provided {@link ParseContext}.
293291
*/
294-
public Mapper parse(ParseContext context) throws IOException {
292+
public void parse(ParseContext context) throws IOException {
295293
final List<IndexableField> fields = new ArrayList<>(2);
296294
try {
297295
parseCreateField(context, fields);
@@ -303,7 +301,6 @@ public Mapper parse(ParseContext context) throws IOException {
303301
fieldType().typeName());
304302
}
305303
multiFields.parse(this, context);
306-
return null;
307304
}
308305

309306
/**

server/src/main/java/org/elasticsearch/index/mapper/FieldNamesFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,8 @@ public void postParse(ParseContext context) throws IOException {
225225
}
226226

227227
@Override
228-
public Mapper parse(ParseContext context) throws IOException {
228+
public void parse(ParseContext context) throws IOException {
229229
// Adding values to the _field_names field is handled by the mappers for each field type
230-
return null;
231230
}
232231

233232
static Iterable<String> extractFieldNames(final String fullPath) {

server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ protected void parse(ParseContext originalContext, GeoPoint point) throws IOExce
285285
}
286286

287287
@Override
288-
public Mapper parse(ParseContext context) throws IOException {
288+
public void parse(ParseContext context) throws IOException {
289289
context.path().add(simpleName());
290290

291291
GeoPoint sparse = context.parseExternalValue(GeoPoint.class);
@@ -340,7 +340,6 @@ public Mapper parse(ParseContext context) throws IOException {
340340
}
341341

342342
context.path().remove();
343-
return null;
344343
}
345344

346345
/**

server/src/main/java/org/elasticsearch/index/mapper/GeoShapeFieldMapper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,13 @@ public GeoShapeFieldType fieldType() {
492492
return (GeoShapeFieldType) super.fieldType();
493493
}
494494
@Override
495-
public Mapper parse(ParseContext context) throws IOException {
495+
public void parse(ParseContext context) throws IOException {
496496
try {
497497
Shape shape = context.parseExternalValue(Shape.class);
498498
if (shape == null) {
499499
ShapeBuilder shapeBuilder = ShapeParser.parse(context.parser(), this);
500500
if (shapeBuilder == null) {
501-
return null;
501+
return;
502502
}
503503
shape = shapeBuilder.build();
504504
}
@@ -510,7 +510,7 @@ public Mapper parse(ParseContext context) throws IOException {
510510
for (Shape s : shapes) {
511511
indexShape(context, s);
512512
}
513-
return null;
513+
return;
514514
} else if (shape instanceof Point == false) {
515515
throw new MapperParsingException("[{" + fieldType().name() + "}] is configured for points only but a " +
516516
((shape instanceof JtsGeometry) ? ((JtsGeometry)shape).getGeom().getGeometryType() : shape.getClass()) + " was found");
@@ -524,7 +524,6 @@ public Mapper parse(ParseContext context) throws IOException {
524524
}
525525
context.addIgnoredField(fieldType.name());
526526
}
527-
return null;
528527
}
529528

530529
private void indexShape(ParseContext context, Shape shape) {

server/src/main/java/org/elasticsearch/index/mapper/IgnoredFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ public void postParse(ParseContext context) throws IOException {
129129
}
130130

131131
@Override
132-
public Mapper parse(ParseContext context) throws IOException {
132+
public void parse(ParseContext context) throws IOException {
133133
// done in post-parse
134-
return null;
135134
}
136135

137136
@Override

server/src/main/java/org/elasticsearch/index/mapper/RoutingFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,10 @@ public void preParse(ParseContext context) throws IOException {
157157
}
158158

159159
@Override
160-
public Mapper parse(ParseContext context) throws IOException {
160+
public void parse(ParseContext context) throws IOException {
161161
// no need ot parse here, we either get the routing in the sourceToParse
162162
// or we don't have routing, if we get it in sourceToParse, we process it in preParse
163163
// which will always be called
164-
return null;
165164
}
166165

167166
@Override

server/src/main/java/org/elasticsearch/index/mapper/SeqNoFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,8 @@ protected void parseCreateField(ParseContext context, List<IndexableField> field
242242
}
243243

244244
@Override
245-
public Mapper parse(ParseContext context) throws IOException {
245+
public void parse(ParseContext context) throws IOException {
246246
// fields are added in parseCreateField
247-
return null;
248247
}
249248

250249
@Override

server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ public void preParse(ParseContext context) throws IOException {
223223
}
224224

225225
@Override
226-
public Mapper parse(ParseContext context) throws IOException {
226+
public void parse(ParseContext context) throws IOException {
227227
// nothing to do here, we will call it in pre parse
228-
return null;
229228
}
230229

231230
@Override

server/src/main/java/org/elasticsearch/index/mapper/TypeFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,8 @@ public void preParse(ParseContext context) throws IOException {
322322
}
323323

324324
@Override
325-
public Mapper parse(ParseContext context) throws IOException {
325+
public void parse(ParseContext context) throws IOException {
326326
// we parse in pre parse
327-
return null;
328327
}
329328

330329
@Override

server/src/main/java/org/elasticsearch/index/mapper/UidFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,8 @@ public void preParse(ParseContext context) throws IOException {
205205
public void postParse(ParseContext context) throws IOException {}
206206

207207
@Override
208-
public Mapper parse(ParseContext context) throws IOException {
208+
public void parse(ParseContext context) throws IOException {
209209
// nothing to do here, we do everything in preParse
210-
return null;
211210
}
212211

213212
@Override

server/src/main/java/org/elasticsearch/index/mapper/VersionFieldMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ protected void parseCreateField(ParseContext context, List<IndexableField> field
117117
}
118118

119119
@Override
120-
public Mapper parse(ParseContext context) throws IOException {
120+
public void parse(ParseContext context) throws IOException {
121121
// _version added in preparse
122-
return null;
123122
}
124123

125124
@Override

server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public ExternalMapper(String simpleName, MappedFieldType fieldType,
168168
}
169169

170170
@Override
171-
public Mapper parse(ParseContext context) throws IOException {
171+
public void parse(ParseContext context) throws IOException {
172172
byte[] bytes = "Hello world".getBytes(Charset.defaultCharset());
173173
binMapper.parse(context.createExternalValueContext(bytes));
174174

@@ -190,7 +190,6 @@ public Mapper parse(ParseContext context) throws IOException {
190190
stringMapper.parse(context);
191191

192192
multiFields.parse(this, context);
193-
return null;
194193
}
195194

196195
@Override

0 commit comments

Comments
 (0)