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 the 'array value parser' marker interface. #57623

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ protected void parseCreateField(ParseContext context, List<IndexableField> field
throw new UnsupportedOperationException("Parsing is implemented in parse(), this method should NEVER be called");
}

@Override
public final boolean parsesArrayValue() {
return true;
}

@Override
public void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException {
super.doXContentBody(builder, includeDefaults, params);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
* This field can also be extended to add search criteria to suggestions
* for query-time filtering and boosting (see {@link ContextMappings}
*/
public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapperParser {
public class CompletionFieldMapper extends FieldMapper {
public static final String CONTENT_TYPE = "completion";

/**
Expand Down Expand Up @@ -441,6 +441,11 @@ public CompletionFieldType fieldType() {
return (CompletionFieldType) super.fieldType();
}

@Override
public boolean parsesArrayValue() {
return true;
}

/**
* Parses and indexes inputs
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ private static void parseArray(ParseContext context, ObjectMapper parentMapper,
// There is a concrete mapper for this field already. Need to check if the mapper
// expects an array, if so we pass the context straight to the mapper and if not
// we serialize the array components
if (mapper instanceof ArrayValueMapperParser) {
if (parsesArrayValue(mapper)) {
parseObjectOrField(context, mapper);
} else {
parseNonDynamicArray(context, parentMapper, lastFieldName, arrayFieldName);
Expand All @@ -562,7 +562,7 @@ private static void parseArray(ParseContext context, ObjectMapper parentMapper,
Mapper.BuilderContext builderContext = new Mapper.BuilderContext(context.indexSettings().getSettings(), context.path());
mapper = builder.build(builderContext);
assert mapper != null;
if (mapper instanceof ArrayValueMapperParser) {
if (parsesArrayValue(mapper)) {
context.addDynamicMapper(mapper);
context.path().add(arrayFieldName);
parseObjectOrField(context, mapper);
Expand All @@ -581,6 +581,10 @@ private static void parseArray(ParseContext context, ObjectMapper parentMapper,
}
}

private static boolean parsesArrayValue(Mapper mapper) {
return mapper instanceof FieldMapper && ((FieldMapper) mapper).parsesArrayValue();
}

private static void parseNonDynamicArray(ParseContext context, ObjectMapper mapper,
final String lastFieldName, String arrayFieldName) throws IOException {
XContentParser parser = context.parser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ public CopyTo copyTo() {
return copyTo;
}

/**
* Whether this mapper can handle an array value during document parsing. If true,
* when an array is encountered during parsing, the document parser will pass the
* whole array to the mapper. If false, the array is split into individual values
* and each value is passed to the mapper for parsing.
*/
public boolean parsesArrayValue() {
return false;
}

/**
* Parse the field value using the provided {@link ParseContext}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
*
* Uses lucene 6 LatLonPoint encoding
*/
public class GeoPointFieldMapper extends AbstractGeometryFieldMapper implements ArrayValueMapperParser {
public class GeoPointFieldMapper extends AbstractGeometryFieldMapper {
public static final String CONTENT_TYPE = "geo_point";

public static class Names extends AbstractGeometryFieldMapper.Names {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
import org.elasticsearch.index.mapper.ArrayValueMapperParser;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
Expand All @@ -40,7 +39,7 @@
*
* Uses lucene 8 XYPoint encoding
*/
public class PointFieldMapper extends AbstractGeometryFieldMapper implements ArrayValueMapperParser {
public class PointFieldMapper extends AbstractGeometryFieldMapper {
public static final String CONTENT_TYPE = "point";

public static class Names extends AbstractGeometryFieldMapper.Names {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.mapper.ArrayValueMapperParser;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
Expand All @@ -42,7 +41,7 @@
/**
* A {@link FieldMapper} for indexing a dense vector of floats.
*/
public class DenseVectorFieldMapper extends FieldMapper implements ArrayValueMapperParser {
public class DenseVectorFieldMapper extends FieldMapper {

public static final String CONTENT_TYPE = "dense_vector";
public static short MAX_DIMS_COUNT = 2048; //maximum allowed number of dimensions
Expand Down Expand Up @@ -180,6 +179,11 @@ public DenseVectorFieldType fieldType() {
return (DenseVectorFieldType) super.fieldType();
}

@Override
public boolean parsesArrayValue() {
return true;
}

@Override
public void parse(ParseContext context) throws IOException {
if (context.externalValueSet()) {
Expand Down