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. #57571

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 @@ -305,6 +305,11 @@ protected void parseCreateField(ParseContext context) throws IOException {
protected abstract void addDocValuesFields(String name, Processed geometry, List<IndexableField> fields, ParseContext context);
protected abstract void addMultiFields(ParseContext context, Processed geometry) throws IOException;

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

/** parsing logic for geometry indexing */
@Override
public void parse(ParseContext context) throws IOException {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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 @@ -426,6 +426,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 @@ -522,7 +522,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 @@ -543,7 +543,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 @@ -562,6 +562,10 @@ private static void parseArray(ParseContext context, ObjectMapper parentMapper,
}
}

private static boolean parsesArrayValue(Mapper mapper) {
return mapper instanceof FieldMapper && ((FieldMapper) mapper).parsesArrayValue();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately this refactor didn't actually cut down on the number of instanceof checks. But I feel better about this one, because it's very common for us to check instanceof against FieldMapper or ObjectMapper -- it's just part of how mappings + document parsing currently work.

}

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 @@ -273,6 +273,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 @@ -44,8 +44,7 @@
*
* Uses lucene 6 LatLonPoint encoding
*/
public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<List<? extends GeoPoint>, List<? extends GeoPoint>>
implements ArrayValueMapperParser {
public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<List<? extends GeoPoint>, List<? extends GeoPoint>> {
public static final String CONTENT_TYPE = "geo_point";

public static class Builder extends AbstractPointGeometryFieldMapper.Builder<Builder, GeoPointFieldType> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.mapper.AbstractPointGeometryFieldMapper;
import org.elasticsearch.index.mapper.ArrayValueMapperParser;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.xpack.spatial.common.CartesianPoint;
Expand All @@ -30,8 +29,7 @@
*
* Uses lucene 8 XYPoint encoding
*/
public class PointFieldMapper extends AbstractPointGeometryFieldMapper<List<? extends CartesianPoint>, List<? extends CartesianPoint>>
implements ArrayValueMapperParser {
public class PointFieldMapper extends AbstractPointGeometryFieldMapper<List<? extends CartesianPoint>, List<? extends CartesianPoint>> {
public static final String CONTENT_TYPE = "point";

public static class Builder extends AbstractPointGeometryFieldMapper.Builder<Builder, PointFieldType> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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 @@ -40,7 +39,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 @@ -173,6 +172,11 @@ public DenseVectorFieldType fieldType() {
return (DenseVectorFieldType) super.fieldType();
}

@Override
public boolean parsesArrayValue() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be final, like AbstractGeometryFieldMapper does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To me this could be a bit confusing, because no other methods on DenseVectorFieldType are final and it wasn't designed for extension.

return true;
}

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