Skip to content

Commit

Permalink
Correct type parametrization in geo mappers. (#59583)
Browse files Browse the repository at this point in the history
Previously the concrete type parameters for the MappedFieldType didn't always
match those for the FieldMapper. This PR updates the mappers so that the type
parameters always match, which makes the design easier to follow.
  • Loading branch information
jtibshirani authored Jul 15, 2020
1 parent c51d765 commit fd88ab1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,9 @@ protected void mergeOptions(FieldMapper other, List<String> conflicts) {
}

@Override
public AbstractGeometryFieldType fieldType() {
return (AbstractGeometryFieldType)mappedFieldType;
@SuppressWarnings("unchecked")
public AbstractGeometryFieldType<Parsed, Processed> fieldType() {
return (AbstractGeometryFieldType<Parsed, Processed>) mappedFieldType;
}

@Override
Expand All @@ -282,10 +283,10 @@ protected void parseCreateField(ParseContext context) throws IOException {
/** parsing logic for geometry indexing */
@Override
public void parse(ParseContext context) throws IOException {
AbstractGeometryFieldMapper.AbstractGeometryFieldType mappedFieldType = fieldType();
AbstractGeometryFieldType<Parsed, Processed> mappedFieldType = fieldType();

@SuppressWarnings("unchecked") Indexer<Parsed, Processed> geometryIndexer = mappedFieldType.geometryIndexer();
@SuppressWarnings("unchecked") Parser<Parsed> geometryParser = mappedFieldType.geometryParser();
Indexer<Parsed, Processed> geometryIndexer = mappedFieldType.geometryIndexer();
Parser<Parsed> geometryParser = mappedFieldType.geometryParser();
try {
Processed shape = context.parseExternalValue(geometryIndexer.processedClass());
if (shape == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.AbstractLatLonPointIndexFieldData;
import org.elasticsearch.index.query.VectorGeoPointShapeQueryProcessor;
import org.elasticsearch.index.mapper.GeoPointFieldMapper.ParsedGeoPoint;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;

import java.io.IOException;
Expand All @@ -45,7 +46,7 @@
*
* Uses lucene 6 LatLonPoint encoding
*/
public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<List<? extends GeoPoint>, List<? extends GeoPoint>> {
public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<List<ParsedGeoPoint>, List<? extends GeoPoint>> {
public static final String CONTENT_TYPE = "geo_point";
public static final FieldType FIELD_TYPE = new FieldType();
static {
Expand Down Expand Up @@ -163,7 +164,7 @@ protected ParsedPoint newParsedPoint() {
return new ParsedGeoPoint();
}

public static class GeoPointFieldType extends AbstractPointGeometryFieldType<List<ParsedGeoPoint>, List<ParsedGeoPoint>> {
public static class GeoPointFieldType extends AbstractPointGeometryFieldType<List<ParsedGeoPoint>, List<? extends GeoPoint>> {
public GeoPointFieldType(String name, boolean indexed, boolean hasDocValues, Map<String, String> meta) {
super(name, indexed, hasDocValues, meta);
}
Expand Down Expand Up @@ -242,7 +243,7 @@ public int hashCode() {
}
}

protected static class GeoPointIndexer implements Indexer<List<ParsedGeoPoint>, List<ParsedGeoPoint>> {
protected static class GeoPointIndexer implements Indexer<List<ParsedGeoPoint>, List<? extends GeoPoint>> {

protected final GeoPointFieldType fieldType;

Expand All @@ -251,20 +252,20 @@ protected static class GeoPointIndexer implements Indexer<List<ParsedGeoPoint>,
}

@Override
public List<ParsedGeoPoint> prepareForIndexing(List<ParsedGeoPoint> geoPoints) {
public List<? extends GeoPoint> prepareForIndexing(List<ParsedGeoPoint> geoPoints) {
if (geoPoints == null || geoPoints.isEmpty()) {
return Collections.emptyList();
}
return geoPoints;
}

@Override
public Class<List<ParsedGeoPoint>> processedClass() {
return (Class<List<ParsedGeoPoint>>)(Object)List.class;
public Class<List<? extends GeoPoint>> processedClass() {
return (Class<List<? extends GeoPoint>>)(Object)List.class;
}

@Override
public List<IndexableField> indexShape(ParseContext context, List<ParsedGeoPoint> points) {
public List<IndexableField> indexShape(ParseContext context, List<? extends GeoPoint> points) {
ArrayList<IndexableField> fields = new ArrayList<>(points.size());
for (GeoPoint point : points) {
fields.add(new LatLonPoint(fieldType.name(), point.lat(), point.lon()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.xpack.spatial.common.CartesianPoint;
import org.elasticsearch.xpack.spatial.index.query.ShapeQueryPointProcessor;
import org.elasticsearch.xpack.spatial.index.mapper.PointFieldMapper.ParsedCartesianPoint;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -29,7 +30,7 @@
*
* Uses lucene 8 XYPoint encoding
*/
public class PointFieldMapper extends AbstractPointGeometryFieldMapper<List<? extends CartesianPoint>, List<? extends CartesianPoint>> {
public class PointFieldMapper extends AbstractPointGeometryFieldMapper<List<ParsedCartesianPoint>, List<? extends CartesianPoint>> {
public static final String CONTENT_TYPE = "point";

public static class Builder extends AbstractPointGeometryFieldMapper.Builder<Builder, PointFieldType> {
Expand Down Expand Up @@ -95,15 +96,13 @@ public PointFieldMapper(String simpleName, FieldType fieldType, MappedFieldType
}

@Override
@SuppressWarnings("unchecked")
protected void addStoredFields(ParseContext context, List<? extends CartesianPoint> points) {
for (CartesianPoint point : points) {
context.doc().add(new StoredField(fieldType().name(), point.toString()));
}
}

@Override
@SuppressWarnings("unchecked")
protected void addDocValuesFields(String name, List<? extends CartesianPoint> points, List<IndexableField> fields,
ParseContext context) {
for (CartesianPoint point : points) {
Expand All @@ -123,10 +122,10 @@ protected String contentType() {

@Override
public PointFieldType fieldType() {
return (PointFieldType)mappedFieldType;
return (PointFieldType) mappedFieldType;
}

public static class PointFieldType extends AbstractPointGeometryFieldType<List<ParsedCartesianPoint>, List<ParsedCartesianPoint>> {
public static class PointFieldType extends AbstractPointGeometryFieldType<List<ParsedCartesianPoint>, List<? extends CartesianPoint>> {
public PointFieldType(String name, boolean indexed, boolean hasDocValues, Map<String, String> meta) {
super(name, indexed, hasDocValues, meta);
}
Expand Down Expand Up @@ -190,15 +189,15 @@ public int hashCode() {
}
}

protected static class PointIndexer implements Indexer<List<ParsedCartesianPoint>, List<ParsedCartesianPoint>> {
protected static class PointIndexer implements Indexer<List<ParsedCartesianPoint>, List<? extends CartesianPoint>> {
protected final PointFieldType fieldType;

PointIndexer(PointFieldType fieldType) {
this.fieldType = fieldType;
}

@Override
public List<ParsedCartesianPoint> prepareForIndexing(List<ParsedCartesianPoint> points) {
public List<? extends CartesianPoint> prepareForIndexing(List<ParsedCartesianPoint> points) {
if (points == null || points.isEmpty()) {
return Collections.emptyList();
}
Expand All @@ -207,14 +206,14 @@ public List<ParsedCartesianPoint> prepareForIndexing(List<ParsedCartesianPoint>

@Override
@SuppressWarnings("unchecked")
public Class<List<ParsedCartesianPoint>> processedClass() {
return (Class<List<ParsedCartesianPoint>>)(Object)List.class;
public Class<List<? extends CartesianPoint>> processedClass() {
return (Class<List<? extends CartesianPoint>>)(Object)List.class;
}

@Override
public List<IndexableField> indexShape(ParseContext context, List<ParsedCartesianPoint> points) {
public List<IndexableField> indexShape(ParseContext context, List<? extends CartesianPoint> points) {
ArrayList<IndexableField> fields = new ArrayList<>(1);
for (ParsedCartesianPoint point : points) {
for (CartesianPoint point : points) {
fields.add(new XYPointField(fieldType.name(), point.getX(), point.getY()));
}
return fields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public Builder newBuilder(String name, Map<String, Object> params) {
}
}

@SuppressWarnings({"unchecked", "rawtypes"})
public static final class ShapeFieldType extends AbstractShapeGeometryFieldType {
public static final class ShapeFieldType extends AbstractShapeGeometryFieldType<Geometry, Geometry> {
public ShapeFieldType(String name, boolean indexed, boolean hasDocValues, Map<String, String> meta) {
super(name, indexed, hasDocValues, meta);
}
Expand Down

0 comments on commit fd88ab1

Please sign in to comment.