From 34fd6e18bbef57e0aa2a02cfafdc7603cd20a8f7 Mon Sep 17 00:00:00 2001 From: Ignacio Vera Date: Thu, 15 Sep 2022 16:16:32 +0200 Subject: [PATCH] Remove ShapeValues from Geo specific classes in favour of GeoShapeValues (#90100) --- .../search/GeoShapeScriptDocValuesIT.java | 14 ++--- .../index/fielddata/GeoShapeValues.java | 2 +- .../index/fielddata/IndexShapeFieldData.java | 2 +- .../index/fielddata/LeafShapeFieldData.java | 51 ++++--------------- .../spatial/index/fielddata/ShapeValues.java | 14 ++--- .../AbstractAtomicGeoShapeShapeFieldData.java | 48 +++++++++++++---- .../plain/AbstractShapeIndexFieldData.java | 12 ++--- .../LatLonShapeDVAtomicShapeFieldData.java | 7 ++- .../plain/LatLonShapeIndexFieldData.java | 8 +-- .../GeoShapeWithDocValuesFieldMapper.java | 24 ++++----- .../geogrid/AbstractGeoHashGridTiler.java | 18 ++++--- .../geogrid/AbstractGeoTileGridTiler.java | 9 ++-- .../bucket/geogrid/GeoGridTiler.java | 4 +- .../bucket/geogrid/GeoShapeCellIdSource.java | 4 +- .../bucket/geogrid/GeoShapeCellValues.java | 6 +-- .../metrics/GeoShapeBoundsAggregator.java | 5 +- .../metrics/GeoShapeCentroidAggregator.java | 6 +-- .../support/GeoShapeValuesSource.java | 9 ++-- .../support/GeoShapeValuesSourceType.java | 7 ++- .../support/ShapeValuesSource.java | 6 +-- 20 files changed, 124 insertions(+), 132 deletions(-) diff --git a/x-pack/plugin/spatial/src/internalClusterTest/java/org/elasticsearch/xpack/spatial/search/GeoShapeScriptDocValuesIT.java b/x-pack/plugin/spatial/src/internalClusterTest/java/org/elasticsearch/xpack/spatial/search/GeoShapeScriptDocValuesIT.java index f41f78587cbf8..73314c9ecfdcc 100644 --- a/x-pack/plugin/spatial/src/internalClusterTest/java/org/elasticsearch/xpack/spatial/search/GeoShapeScriptDocValuesIT.java +++ b/x-pack/plugin/spatial/src/internalClusterTest/java/org/elasticsearch/xpack/spatial/search/GeoShapeScriptDocValuesIT.java @@ -81,7 +81,7 @@ protected Map, Object>> pluginScripts() { private double scriptHeight(Map vars) { Map doc = (Map) vars.get("doc"); - LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); + LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); if (geometry.size() == 0) { return Double.NaN; } else { @@ -92,7 +92,7 @@ private double scriptHeight(Map vars) { private double scriptWidth(Map vars) { Map doc = (Map) vars.get("doc"); - LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); + LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); if (geometry.size() == 0) { return Double.NaN; } else { @@ -103,29 +103,29 @@ private double scriptWidth(Map vars) { private double scriptLat(Map vars) { Map doc = (Map) vars.get("doc"); - LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); + LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); return geometry.size() == 0 ? Double.NaN : geometry.getCentroid().lat(); } private double scriptLon(Map vars) { Map doc = (Map) vars.get("doc"); - LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); + LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); return geometry.size() == 0 ? Double.NaN : geometry.getCentroid().lon(); } private double scriptLabelLat(Map vars) { Map doc = (Map) vars.get("doc"); - LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); + LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); return geometry.size() == 0 ? Double.NaN : geometry.getLabelPosition().lat(); } private double scriptLabelLon(Map vars) { Map doc = (Map) vars.get("doc"); - LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); + LeafShapeFieldData.ShapeScriptValues geometry = assertGeometry(doc); return geometry.size() == 0 ? Double.NaN : geometry.getLabelPosition().lon(); } - private LeafShapeFieldData.ShapeScriptValues assertGeometry(Map doc) { + private LeafShapeFieldData.ShapeScriptValues assertGeometry(Map doc) { AbstractAtomicGeoShapeShapeFieldData.GeoShapeScriptValues geometry = (AbstractAtomicGeoShapeShapeFieldData.GeoShapeScriptValues) doc.get("location"); if (geometry.size() == 0) { diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoShapeValues.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoShapeValues.java index d247ae53a9dcc..221bddca2c7e5 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoShapeValues.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoShapeValues.java @@ -33,7 +33,7 @@ * * There is just one value for one document. */ -public abstract class GeoShapeValues extends ShapeValues { +public abstract class GeoShapeValues extends ShapeValues { public static GeoShapeValues EMPTY = new GeoShapeValues() { private final GeoShapeValuesSourceType DEFAULT_VALUES_SOURCE_TYPE = GeoShapeValuesSourceType.instance(); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/IndexShapeFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/IndexShapeFieldData.java index 302dd53ac2527..314b739c8d744 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/IndexShapeFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/IndexShapeFieldData.java @@ -12,4 +12,4 @@ /** * Specialization of {@link IndexFieldData} for geo shapes and shapes. */ -public interface IndexShapeFieldData extends IndexFieldData {} +public interface IndexShapeFieldData> extends IndexFieldData> {} diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/LeafShapeFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/LeafShapeFieldData.java index 7b67d614a00e0..9001496ce35c8 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/LeafShapeFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/LeafShapeFieldData.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.spatial.index.fielddata; -import org.apache.lucene.util.Accountable; import org.elasticsearch.common.geo.BoundingBox; import org.elasticsearch.common.geo.SpatialPoint; import org.elasticsearch.index.fielddata.LeafFieldData; @@ -16,50 +15,20 @@ import org.elasticsearch.script.field.DocValuesScriptFieldFactory; import org.elasticsearch.script.field.ToScriptFieldFactory; -import java.util.Collection; -import java.util.Collections; - /** * {@link LeafFieldData} specialization for geo-shapes and shapes. */ -public abstract class LeafShapeFieldData implements LeafFieldData { - protected final ToScriptFieldFactory toScriptFieldFactory; +public abstract class LeafShapeFieldData> implements LeafFieldData { + protected final ToScriptFieldFactory toScriptFieldFactory; - public LeafShapeFieldData(ToScriptFieldFactory toScriptFieldFactory) { + public LeafShapeFieldData(ToScriptFieldFactory toScriptFieldFactory) { this.toScriptFieldFactory = toScriptFieldFactory; } - public static class Empty extends LeafShapeFieldData { - private final ShapeValues emptyValues; - - public Empty(ToScriptFieldFactory toScriptFieldFactory, ShapeValues emptyValues) { - super(toScriptFieldFactory); - this.emptyValues = emptyValues; - } - - @Override - public long ramBytesUsed() { - return 0; - } - - @Override - public Collection getChildResources() { - return Collections.emptyList(); - } - - @Override - public void close() {} - - @Override - public ShapeValues getShapeValues() { - return emptyValues; - } - } - /** * Return geo-shape or shape values. */ - public abstract ShapeValues getShapeValues(); + public abstract T getShapeValues(); @Override public final SortedBinaryDocValues getBytesValues() { @@ -71,11 +40,13 @@ public final DocValuesScriptFieldFactory getScriptFieldFactory(String name) { return toScriptFieldFactory.getScriptFieldFactory(getShapeValues(), name); } - public static class ShapeScriptValues extends ScriptDocValues.BaseGeometry { + public static class ShapeScriptValues extends ScriptDocValues.BaseGeometry< + T, + V> { - private final GeometrySupplier gsSupplier; + private final GeometrySupplier gsSupplier; - protected ShapeScriptValues(GeometrySupplier supplier) { + protected ShapeScriptValues(GeometrySupplier supplier) { super(supplier); this.gsSupplier = supplier; } @@ -101,11 +72,11 @@ public T getLabelPosition() { } @Override - public ShapeValues.ShapeValue get(int index) { + public V get(int index) { return gsSupplier.getInternal(0); } - public ShapeValues.ShapeValue getValue() { + public V getValue() { return gsSupplier.getInternal(0); } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/ShapeValues.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/ShapeValues.java index b5c5f6a2d9693..05278b6353909 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/ShapeValues.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/ShapeValues.java @@ -41,15 +41,15 @@ * * There is just one value for one document. */ -public abstract class ShapeValues { +public abstract class ShapeValues { protected final CoordinateEncoder encoder; - protected final Supplier supplier; + protected final Supplier supplier; protected final ShapeIndexer missingShapeIndexer; /** * Creates a new {@link ShapeValues} instance */ - protected ShapeValues(CoordinateEncoder encoder, Supplier supplier, ShapeIndexer missingShapeIndexer) { + protected ShapeValues(CoordinateEncoder encoder, Supplier supplier, ShapeIndexer missingShapeIndexer) { this.encoder = encoder; this.supplier = supplier; this.missingShapeIndexer = missingShapeIndexer; @@ -70,14 +70,14 @@ protected ShapeValues(CoordinateEncoder encoder, Supplier supplier, * * @return the value for the current docID set to {@link #advanceExact(int)}. */ - public abstract ShapeValue value() throws IOException; + public abstract T value() throws IOException; - public ShapeValue missing(String missing) { + public T missing(String missing) { try { final Geometry geometry = WellKnownText.fromWKT(GeographyValidator.instance(true), true, missing); final BinaryShapeDocValuesField field = new BinaryShapeDocValuesField("missing", encoder); field.add(missingShapeIndexer.indexShape(geometry), geometry); - final ShapeValue value = supplier.get(); + final T value = supplier.get(); value.reset(field.binaryValue()); return value; } catch (IOException | ParseException e) { @@ -87,7 +87,7 @@ public ShapeValue missing(String missing) { /** thin wrapper around a {@link GeometryDocValueReader} which encodes / decodes values using * the Geo decoder */ - public abstract static class ShapeValue implements ToXContentFragment { + protected abstract static class ShapeValue implements ToXContentFragment { protected final GeometryDocValueReader reader; private final BoundingBox boundingBox; private final Tile2DVisitor tile2DVisitor; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/AbstractAtomicGeoShapeShapeFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/AbstractAtomicGeoShapeShapeFieldData.java index 93f237141a8ec..34f4a9ea6f9f5 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/AbstractAtomicGeoShapeShapeFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/AbstractAtomicGeoShapeShapeFieldData.java @@ -7,43 +7,73 @@ package org.elasticsearch.xpack.spatial.index.fielddata.plain; +import org.apache.lucene.util.Accountable; import org.elasticsearch.common.geo.GeoBoundingBox; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.script.field.ToScriptFieldFactory; import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; import org.elasticsearch.xpack.spatial.index.fielddata.LeafShapeFieldData; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; + +import java.util.Collection; +import java.util.Collections; import static org.elasticsearch.common.geo.SphericalMercatorUtils.latToSphericalMercator; import static org.elasticsearch.common.geo.SphericalMercatorUtils.lonToSphericalMercator; -public abstract class AbstractAtomicGeoShapeShapeFieldData extends LeafShapeFieldData { +public abstract class AbstractAtomicGeoShapeShapeFieldData extends LeafShapeFieldData { + + private static class Empty extends AbstractAtomicGeoShapeShapeFieldData { + private final GeoShapeValues emptyValues; + + Empty(ToScriptFieldFactory toScriptFieldFactory, GeoShapeValues emptyValues) { + super(toScriptFieldFactory); + this.emptyValues = emptyValues; + } + + @Override + public long ramBytesUsed() { + return 0; + } + + @Override + public Collection getChildResources() { + return Collections.emptyList(); + } + + @Override + public void close() {} + + @Override + public GeoShapeValues getShapeValues() { + return emptyValues; + } + } - public AbstractAtomicGeoShapeShapeFieldData(ToScriptFieldFactory toScriptFieldFactory) { + public AbstractAtomicGeoShapeShapeFieldData(ToScriptFieldFactory toScriptFieldFactory) { super(toScriptFieldFactory); } - public static LeafShapeFieldData empty(final int maxDoc, ToScriptFieldFactory toScriptFieldFactory) { - return new LeafShapeFieldData.Empty<>(toScriptFieldFactory, GeoShapeValues.EMPTY); + public static AbstractAtomicGeoShapeShapeFieldData empty(final int maxDoc, ToScriptFieldFactory toScriptFieldFactory) { + return new Empty(toScriptFieldFactory, GeoShapeValues.EMPTY); } - public static final class GeoShapeScriptValues extends LeafShapeFieldData.ShapeScriptValues + public static final class GeoShapeScriptValues extends LeafShapeFieldData.ShapeScriptValues implements ScriptDocValues.Geometry { - public GeoShapeScriptValues(GeometrySupplier supplier) { + public GeoShapeScriptValues(GeometrySupplier supplier) { super(supplier); } @Override public GeoShapeValues.GeoShapeValue get(int index) { - return (GeoShapeValues.GeoShapeValue) super.get(index); + return super.get(index); } @Override public GeoShapeValues.GeoShapeValue getValue() { - return (GeoShapeValues.GeoShapeValue) super.getValue(); + return super.getValue(); } @Override diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/AbstractShapeIndexFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/AbstractShapeIndexFieldData.java index 61239429da6ee..ba3752b969db9 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/AbstractShapeIndexFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/AbstractShapeIndexFieldData.java @@ -29,16 +29,12 @@ * `ValueSourceType` that this is constructed with. For example, the `LatLonShapeIndexFieldData.load(context)` method will * create an instance of `LatLonShapeDVAtomicShapeFieldData`. */ -public abstract class AbstractShapeIndexFieldData implements IndexShapeFieldData { +public abstract class AbstractShapeIndexFieldData> implements IndexShapeFieldData { protected final String fieldName; protected final ValuesSourceType valuesSourceType; - protected final ToScriptFieldFactory toScriptFieldFactory; + protected final ToScriptFieldFactory toScriptFieldFactory; - AbstractShapeIndexFieldData( - String fieldName, - ValuesSourceType valuesSourceType, - ToScriptFieldFactory toScriptFieldFactory - ) { + AbstractShapeIndexFieldData(String fieldName, ValuesSourceType valuesSourceType, ToScriptFieldFactory toScriptFieldFactory) { this.fieldName = fieldName; this.valuesSourceType = valuesSourceType; this.toScriptFieldFactory = toScriptFieldFactory; @@ -55,7 +51,7 @@ public ValuesSourceType getValuesSourceType() { } @Override - public LeafShapeFieldData loadDirect(LeafReaderContext context) { + public LeafShapeFieldData loadDirect(LeafReaderContext context) { return load(context); } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LatLonShapeDVAtomicShapeFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LatLonShapeDVAtomicShapeFieldData.java index 75935ad0d3a1c..7fbf90124e001 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LatLonShapeDVAtomicShapeFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LatLonShapeDVAtomicShapeFieldData.java @@ -15,18 +15,17 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; import org.elasticsearch.xpack.spatial.index.fielddata.LeafShapeFieldData; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType; import java.io.IOException; import java.util.Collection; import java.util.Collections; -final class LatLonShapeDVAtomicShapeFieldData extends LeafShapeFieldData { +final class LatLonShapeDVAtomicShapeFieldData extends LeafShapeFieldData { private final LeafReader reader; private final String fieldName; - LatLonShapeDVAtomicShapeFieldData(LeafReader reader, String fieldName, ToScriptFieldFactory toScriptFieldFactory) { + LatLonShapeDVAtomicShapeFieldData(LeafReader reader, String fieldName, ToScriptFieldFactory toScriptFieldFactory) { super(toScriptFieldFactory); this.reader = reader; this.fieldName = fieldName; @@ -48,7 +47,7 @@ public void close() { } @Override - public ShapeValues getShapeValues() { + public GeoShapeValues getShapeValues() { try { final BinaryDocValues binaryValues = DocValues.getBinary(reader, fieldName); final GeoShapeValues.GeoShapeValue geoShapeValue = new GeoShapeValues.GeoShapeValue(); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LatLonShapeIndexFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LatLonShapeIndexFieldData.java index eb5013da3f7c1..b7412e5696b50 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LatLonShapeIndexFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/plain/LatLonShapeIndexFieldData.java @@ -12,20 +12,20 @@ import org.apache.lucene.index.LeafReaderContext; import org.elasticsearch.script.field.ToScriptFieldFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; import org.elasticsearch.xpack.spatial.index.fielddata.LeafShapeFieldData; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; -public class LatLonShapeIndexFieldData extends AbstractShapeIndexFieldData { +public class LatLonShapeIndexFieldData extends AbstractShapeIndexFieldData { public LatLonShapeIndexFieldData( String fieldName, ValuesSourceType valuesSourceType, - ToScriptFieldFactory toScriptFieldFactory + ToScriptFieldFactory toScriptFieldFactory ) { super(fieldName, valuesSourceType, toScriptFieldFactory); } @Override - public LeafShapeFieldData load(LeafReaderContext context) { + public LeafShapeFieldData load(LeafReaderContext context) { LeafReader reader = context.reader(); FieldInfo info = reader.getFieldInfos().fieldInfo(fieldName); if (info != null) { diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java index 6d7a39e135ebc..d8c355ee2212c 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java @@ -46,8 +46,6 @@ import org.elasticsearch.script.field.Field; import org.elasticsearch.xpack.spatial.index.fielddata.CoordinateEncoder; import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; -import org.elasticsearch.xpack.spatial.index.fielddata.LeafShapeFieldData; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; import org.elasticsearch.xpack.spatial.index.fielddata.plain.AbstractAtomicGeoShapeShapeFieldData; import org.elasticsearch.xpack.spatial.index.fielddata.plain.LatLonShapeIndexFieldData; import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType; @@ -346,13 +344,13 @@ protected void checkIncomingMergeType(FieldMapper mergeWith) { super.checkIncomingMergeType(mergeWith); } - public static class GeoShapeDocValuesField extends AbstractScriptFieldFactory + public static class GeoShapeDocValuesField extends AbstractScriptFieldFactory implements - Field, + Field, DocValuesScriptFieldFactory, - ScriptDocValues.GeometrySupplier { + ScriptDocValues.GeometrySupplier { - private final ShapeValues in; + private final GeoShapeValues in; protected final String name; private GeoShapeValues.GeoShapeValue value; @@ -360,9 +358,9 @@ public static class GeoShapeDocValuesField extends AbstractScriptFieldFactory geoShapeScriptValues; + private AbstractAtomicGeoShapeShapeFieldData.GeoShapeScriptValues geoShapeScriptValues; - public GeoShapeDocValuesField(ShapeValues in, String name) { + public GeoShapeDocValuesField(GeoShapeValues in, String name) { this.in = in; this.name = name; } @@ -370,7 +368,7 @@ public GeoShapeDocValuesField(ShapeValues in, String name) { @Override public void setNextDocId(int docId) throws IOException { if (in.advanceExact(docId)) { - value = (GeoShapeValues.GeoShapeValue) in.value(); + value = in.value(); centroid.reset(value.getY(), value.getX()); boundingBox.topLeft().reset(value.boundingBox().maxY(), value.boundingBox().minX()); boundingBox.bottomRight().reset(value.boundingBox().minY(), value.boundingBox().maxX()); @@ -380,7 +378,7 @@ public void setNextDocId(int docId) throws IOException { } @Override - public ScriptDocValues toScriptDocValues() { + public ScriptDocValues toScriptDocValues() { if (geoShapeScriptValues == null) { geoShapeScriptValues = new AbstractAtomicGeoShapeShapeFieldData.GeoShapeScriptValues(this); } @@ -389,7 +387,7 @@ public ScriptDocValues toScriptDocValues() { } @Override - public ShapeValues.ShapeValue getInternal(int index) { + public GeoShapeValues.GeoShapeValue getInternal(int index) { if (index != 0) { throw new UnsupportedOperationException(); } @@ -446,7 +444,7 @@ public GeoShapeValues.GeoShapeValue get(int index, GeoShapeValues.GeoShapeValue } @Override - public Iterator iterator() { + public Iterator iterator() { return new Iterator<>() { private int index = 0; @@ -456,7 +454,7 @@ public boolean hasNext() { } @Override - public ShapeValues.ShapeValue next() { + public GeoShapeValues.GeoShapeValue next() { if (hasNext() == false) { throw new NoSuchElementException(); } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/AbstractGeoHashGridTiler.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/AbstractGeoHashGridTiler.java index f41292d0325a0..be4ca89e73bad 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/AbstractGeoHashGridTiler.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/AbstractGeoHashGridTiler.java @@ -12,7 +12,6 @@ import org.elasticsearch.geometry.utils.Geohash; import org.elasticsearch.xpack.spatial.index.fielddata.GeoRelation; import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; import java.io.IOException; @@ -34,7 +33,7 @@ public long encode(double x, double y) { } @Override - public int setValues(GeoShapeCellValues values, ShapeValues.ShapeValue geoValue) throws IOException { + public int setValues(GeoShapeCellValues values, GeoShapeValues.GeoShapeValue geoValue) throws IOException { if (precision == 0) { return 1; @@ -52,8 +51,11 @@ public int setValues(GeoShapeCellValues values, ShapeValues.ShapeValue geoValue) return setValuesByRasterization("", values, 0, geoValue); } - protected int setValuesByBruteForceScan(GeoShapeCellValues values, ShapeValues.ShapeValue geoValue, GeoShapeValues.BoundingBox bounds) - throws IOException { + protected int setValuesByBruteForceScan( + GeoShapeCellValues values, + GeoShapeValues.GeoShapeValue geoValue, + GeoShapeValues.BoundingBox bounds + ) throws IOException { // TODO: This way to discover cells inside of a bounding box seems not to work as expected. I can // see that eventually we will be visiting twice the same cell which should not happen. int idx = 0; @@ -78,9 +80,9 @@ protected int setValuesByBruteForceScan(GeoShapeCellValues values, ShapeValues.S } /** - * Sets a singular doc-value for the {@link ShapeValues.ShapeValue}. + * Sets a singular doc-value for the {@link GeoShapeValues.GeoShapeValue}. */ - protected int setValue(GeoShapeCellValues docValues, ShapeValues.ShapeValue geoValue, GeoShapeValues.BoundingBox bounds) + protected int setValue(GeoShapeCellValues docValues, GeoShapeValues.GeoShapeValue geoValue, GeoShapeValues.BoundingBox bounds) throws IOException { String hash = Geohash.stringEncode(bounds.minX(), bounds.minY(), precision); if (relateTile(geoValue, hash) != GeoRelation.QUERY_DISJOINT) { @@ -91,7 +93,7 @@ protected int setValue(GeoShapeCellValues docValues, ShapeValues.ShapeValue geoV return 0; } - private GeoRelation relateTile(ShapeValues.ShapeValue geoValue, String hash) throws IOException { + private GeoRelation relateTile(GeoShapeValues.GeoShapeValue geoValue, String hash) throws IOException { if (validHash(hash)) { final Rectangle rectangle = Geohash.toBoundingBox(hash); int minX = GeoEncodingUtils.encodeLongitude(rectangle.getMinLon()); @@ -103,7 +105,7 @@ private GeoRelation relateTile(ShapeValues.ShapeValue geoValue, String hash) thr return GeoRelation.QUERY_DISJOINT; } - protected int setValuesByRasterization(String hash, GeoShapeCellValues values, int valuesIndex, ShapeValues.ShapeValue geoValue) + protected int setValuesByRasterization(String hash, GeoShapeCellValues values, int valuesIndex, GeoShapeValues.GeoShapeValue geoValue) throws IOException { String[] hashes = Geohash.getSubGeohashes(hash); for (String s : hashes) { diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/AbstractGeoTileGridTiler.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/AbstractGeoTileGridTiler.java index e7d3bc4f91b2c..68717dd8b68a4 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/AbstractGeoTileGridTiler.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/AbstractGeoTileGridTiler.java @@ -11,7 +11,6 @@ import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileUtils; import org.elasticsearch.xpack.spatial.index.fielddata.GeoRelation; import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; import java.io.IOException; @@ -48,7 +47,7 @@ public long encode(double x, double y) { * @return the number of tiles set by the shape */ @Override - public int setValues(GeoShapeCellValues values, ShapeValues.ShapeValue geoValue) throws IOException { + public int setValues(GeoShapeCellValues values, GeoShapeValues.GeoShapeValue geoValue) throws IOException { GeoShapeValues.BoundingBox bounds = geoValue.boundingBox(); assert bounds.minX() <= bounds.maxX(); @@ -76,7 +75,7 @@ public int setValues(GeoShapeCellValues values, ShapeValues.ShapeValue geoValue) } } - private GeoRelation relateTile(ShapeValues.ShapeValue geoValue, int xTile, int yTile, int precision) throws IOException { + private GeoRelation relateTile(GeoShapeValues.GeoShapeValue geoValue, int xTile, int yTile, int precision) throws IOException { if (validTile(xTile, yTile, precision)) { final double tiles = 1 << precision; final int minX = GeoEncodingUtils.encodeLongitude(GeoTileUtils.tileToLon(xTile, tiles)); @@ -113,7 +112,7 @@ protected int setValue(GeoShapeCellValues docValues, int xTile, int yTile) { */ protected int setValuesByBruteForceScan( GeoShapeCellValues values, - ShapeValues.ShapeValue geoValue, + GeoShapeValues.GeoShapeValue geoValue, int minXTile, int minYTile, int maxXTile, @@ -138,7 +137,7 @@ protected int setValuesByRasterization( int zTile, GeoShapeCellValues values, int valuesIndex, - ShapeValues.ShapeValue geoValue + GeoShapeValues.GeoShapeValue geoValue ) throws IOException { zTile++; for (int i = 0; i < 2; i++) { diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoGridTiler.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoGridTiler.java index a85607ccf7f0c..97150fe53d671 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoGridTiler.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoGridTiler.java @@ -7,7 +7,7 @@ package org.elasticsearch.xpack.spatial.search.aggregations.bucket.geogrid; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; +import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; import java.io.IOException; @@ -44,7 +44,7 @@ public int precision() { * * @return the number of cells the geoValue intersects */ - public abstract int setValues(GeoShapeCellValues docValues, ShapeValues.ShapeValue geoValue) throws IOException; + public abstract int setValues(GeoShapeCellValues docValues, GeoShapeValues.GeoShapeValue geoValue) throws IOException; /** Maximum number of cells that can be created by this tiler */ protected abstract long getMaxCells(); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoShapeCellIdSource.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoShapeCellIdSource.java index 03b31e18986ef..bfabcfbdeb2a5 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoShapeCellIdSource.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoShapeCellIdSource.java @@ -13,7 +13,7 @@ import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; +import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSource; import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType; @@ -46,7 +46,7 @@ public boolean isFloatingPoint() { @Override public SortedNumericDocValues longValues(LeafReaderContext ctx) { - ShapeValues geoValues = valuesSource.shapeValues(ctx); + GeoShapeValues geoValues = valuesSource.shapeValues(ctx); ValuesSourceType vs = geoValues.valuesSourceType(); if (GeoShapeValuesSourceType.instance() == vs) { // docValues are geo shapes diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoShapeCellValues.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoShapeCellValues.java index 9849216febce2..ba8d2c11681be 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoShapeCellValues.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/bucket/geogrid/GeoShapeCellValues.java @@ -7,17 +7,17 @@ package org.elasticsearch.xpack.spatial.search.aggregations.bucket.geogrid; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; +import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; import java.io.IOException; import java.util.function.LongConsumer; /** Sorted numeric doc values for geo shapes */ class GeoShapeCellValues extends ByteTrackingSortingNumericDocValues { - private final ShapeValues geoShapeValues; + private final GeoShapeValues geoShapeValues; protected final GeoGridTiler tiler; - protected GeoShapeCellValues(ShapeValues geoShapeValues, GeoGridTiler tiler, LongConsumer circuitBreakerConsumer) { + protected GeoShapeCellValues(GeoShapeValues geoShapeValues, GeoGridTiler tiler, LongConsumer circuitBreakerConsumer) { super(circuitBreakerConsumer); this.geoShapeValues = geoShapeValues; this.tiler = tiler; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregator.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregator.java index 03c4058e2684b..6cded9fdeb00a 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregator.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregator.java @@ -19,7 +19,6 @@ import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSource; import java.io.IOException; @@ -67,13 +66,13 @@ public LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, if (valuesSource == null) { return LeafBucketCollector.NO_OP_COLLECTOR; } - final ShapeValues values = valuesSource.shapeValues(aggCtx.getLeafReaderContext()); + final GeoShapeValues values = valuesSource.shapeValues(aggCtx.getLeafReaderContext()); return new LeafBucketCollectorBase(sub, values) { @Override public void collect(int doc, long bucket) throws IOException { if (values.advanceExact(doc)) { maybeResize(bucket); - final GeoShapeValues.ShapeValue value = values.value(); + final GeoShapeValues.GeoShapeValue value = values.value(); final GeoShapeValues.BoundingBox bounds = value.boundingBox(); tops.set(bucket, Math.max(tops.get(bucket), bounds.top)); bottoms.set(bucket, Math.min(bottoms.get(bucket), bounds.bottom)); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeCentroidAggregator.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeCentroidAggregator.java index 2704f3c0a98b8..0abe857783179 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeCentroidAggregator.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeCentroidAggregator.java @@ -23,7 +23,7 @@ import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.xpack.spatial.index.fielddata.DimensionalShapeType; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; +import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSource; import java.io.IOException; @@ -65,7 +65,7 @@ public LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCtx, if (valuesSource == null) { return LeafBucketCollector.NO_OP_COLLECTOR; } - final ShapeValues values = valuesSource.shapeValues(aggCtx.getLeafReaderContext()); + final GeoShapeValues values = valuesSource.shapeValues(aggCtx.getLeafReaderContext()); final CompensatedSum compensatedSumLat = new CompensatedSum(0, 0); final CompensatedSum compensatedSumLon = new CompensatedSum(0, 0); final CompensatedSum compensatedSumWeight = new CompensatedSum(0, 0); @@ -80,7 +80,7 @@ public void collect(int doc, long bucket) throws IOException { // Compute the sum of double values with Kahan summation algorithm which is more // accurate than naive summation. final DimensionalShapeType shapeType = DimensionalShapeType.fromOrdinalByte(dimensionalShapeTypes.get(bucket)); - final ShapeValues.ShapeValue value = values.value(); + final GeoShapeValues.GeoShapeValue value = values.value(); final int compares = shapeType.compareTo(value.dimensionalShapeType()); // update the sum if (compares < 0) { diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSource.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSource.java index 7367ece5cefa2..1c2dd5714fa6f 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSource.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSource.java @@ -13,12 +13,11 @@ import org.elasticsearch.search.aggregations.AggregationExecutionException; import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; import org.elasticsearch.xpack.spatial.index.fielddata.IndexShapeFieldData; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; import java.io.IOException; import java.util.function.Function; -public abstract class GeoShapeValuesSource extends ShapeValuesSource { +public abstract class GeoShapeValuesSource extends ShapeValuesSource { public static final GeoShapeValuesSource EMPTY = new GeoShapeValuesSource() { @Override @@ -34,9 +33,9 @@ protected Function roundingPreparer() throws IOExce public static class Fielddata extends GeoShapeValuesSource { - protected final IndexShapeFieldData indexFieldData; + protected final IndexShapeFieldData indexFieldData; - public Fielddata(IndexShapeFieldData indexFieldData) { + public Fielddata(IndexShapeFieldData indexFieldData) { this.indexFieldData = indexFieldData; } @@ -45,7 +44,7 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) { return indexFieldData.load(context).getBytesValues(); } - public ShapeValues shapeValues(LeafReaderContext context) { + public GeoShapeValues shapeValues(LeafReaderContext context) { return indexFieldData.load(context).getShapeValues(); } } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSourceType.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSourceType.java index 49b4e9cdf2eda..bffa78f3a21c0 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSourceType.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSourceType.java @@ -20,7 +20,6 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeValues; import org.elasticsearch.xpack.spatial.index.fielddata.IndexShapeFieldData; -import org.elasticsearch.xpack.spatial.index.fielddata.ShapeValues; import org.elasticsearch.xpack.spatial.index.fielddata.plain.LatLonShapeIndexFieldData; import java.io.IOException; @@ -65,11 +64,11 @@ public ValuesSource replaceMissing( AggregationContext context ) { GeoShapeValuesSource shapeValuesSource = (GeoShapeValuesSource) valuesSource; - final ShapeValues.ShapeValue missing = GeoShapeValues.EMPTY.missing(rawMissing.toString()); + final GeoShapeValues.GeoShapeValue missing = GeoShapeValues.EMPTY.missing(rawMissing.toString()); return new GeoShapeValuesSource() { @Override public GeoShapeValues shapeValues(LeafReaderContext context) { - ShapeValues values = shapeValuesSource.shapeValues(context); + GeoShapeValues values = shapeValuesSource.shapeValues(context); return new GeoShapeValues() { private boolean exists; @@ -88,7 +87,7 @@ public ValuesSourceType valuesSourceType() { } @Override - public ShapeValue value() throws IOException { + public GeoShapeValue value() throws IOException { return exists ? values.value() : missing; } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/ShapeValuesSource.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/ShapeValuesSource.java index 4c99845652f8e..b723530826e3b 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/ShapeValuesSource.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/ShapeValuesSource.java @@ -16,8 +16,8 @@ import java.io.IOException; -public abstract class ShapeValuesSource extends ValuesSource { - public abstract ShapeValues shapeValues(LeafReaderContext context); +public abstract class ShapeValuesSource> extends ValuesSource { + public abstract T shapeValues(LeafReaderContext context); @Override public SortedBinaryDocValues bytesValues(LeafReaderContext context) throws IOException { @@ -26,7 +26,7 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext context) throws IOExc @Override public DocValueBits docsWithValue(LeafReaderContext context) { - ShapeValues values = shapeValues(context); + T values = shapeValues(context); return new DocValueBits() { @Override public boolean advanceExact(int doc) throws IOException {