From 96a02089c2249a07a6c26876412f47e6bbde4b1a Mon Sep 17 00:00:00 2001 From: Nick Knize Date: Thu, 23 Apr 2020 15:32:23 -0500 Subject: [PATCH] Refactor GeoShape DocValues in spatial xpack (#55691) This commit refactors geo_shape doc values, fielddata, and utility classes from the single mapper package in x-pack spatial plugin to a package structure that is consistent with the server module. --- .../xpack/spatial/SpatialPlugin.java | 8 +++--- .../mapper => common}/CartesianPoint.java | 3 ++- .../{index/mapper => common}/ShapeUtils.java | 9 +++---- .../AbstractAtomicGeoShapeShapeFieldData.java | 2 +- .../AbstractLatLonShapeDVIndexFieldData.java | 2 +- .../CentroidCalculator.java | 4 +-- .../CoordinateEncoder.java | 4 +-- .../DimensionalShapeType.java | 2 +- .../index/{mapper => fielddata}/Extent.java | 8 +++--- .../{mapper => fielddata}/GeoRelation.java | 2 +- .../GeoShapeCoordinateEncoder.java | 2 +- .../IndexGeoShapeFieldData.java | 2 +- .../LatLonShapeDVAtomicShapeFieldData.java | 5 ++-- .../LeafGeoShapeFieldData.java | 2 +- .../MultiGeoShapeValues.java | 8 +++--- .../TriangleTreeReader.java | 6 ++--- .../TriangleTreeWriter.java | 2 +- .../mapper/BinaryGeoShapeDocValuesField.java | 3 +++ .../GeoShapeWithDocValuesFieldMapper.java | 5 +++- .../index/mapper/PointFieldMapper.java | 1 + .../spatial/index/mapper/ShapeIndexer.java | 1 + .../index/query/ShapeQueryPointProcessor.java | 2 +- .../index/query/ShapeQueryProcessor.java | 2 +- .../metrics/GeoShapeBoundsAggregator.java | 6 ++--- .../support}/GeoShapeValuesSource.java | 4 ++- .../support}/GeoShapeValuesSourceType.java | 10 +++++-- .../CentroidCalculatorTests.java | 8 +++--- .../GeoShapeCoordinateEncoderTests.java | 5 ++-- .../TestCoordinateEncoder.java | 2 +- .../TriangleTreeTests.java | 23 +++++++++++++--- .../index/mapper/PointFieldMapperTests.java | 1 + .../GeoShapeBoundsAggregatorTests.java | 8 +++--- .../xpack/spatial/util/GeoTestUtils.java | 26 ------------------- 33 files changed, 95 insertions(+), 83 deletions(-) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/{index/mapper => common}/CartesianPoint.java (99%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/{index/mapper => common}/ShapeUtils.java (97%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/AbstractAtomicGeoShapeShapeFieldData.java (96%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/AbstractLatLonShapeDVIndexFieldData.java (98%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/CentroidCalculator.java (99%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/CoordinateEncoder.java (84%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/DimensionalShapeType.java (95%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/Extent.java (98%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/GeoRelation.java (87%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/GeoShapeCoordinateEncoder.java (95%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/IndexGeoShapeFieldData.java (88%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/LatLonShapeDVAtomicShapeFieldData.java (92%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/LeafGeoShapeFieldData.java (90%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/MultiGeoShapeValues.java (95%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/TriangleTreeReader.java (99%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/TriangleTreeWriter.java (99%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/{ => search}/aggregations/metrics/GeoShapeBoundsAggregator.java (96%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/{index/mapper => search/aggregations/support}/GeoShapeValuesSource.java (90%) rename x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/{index/mapper => search/aggregations/support}/GeoShapeValuesSourceType.java (92%) rename x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/CentroidCalculatorTests.java (98%) rename x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/GeoShapeCoordinateEncoderTests.java (91%) rename x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/TestCoordinateEncoder.java (93%) rename x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/{mapper => fielddata}/TriangleTreeTests.java (94%) rename x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/{ => search}/aggregations/metrics/GeoShapeBoundsAggregatorTests.java (97%) diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java index 4d63dceab33..ab7d76dcd32 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java @@ -16,14 +16,14 @@ import org.elasticsearch.search.aggregations.metrics.GeoBoundsAggregationBuilder import org.elasticsearch.search.aggregations.metrics.GeoBoundsAggregatorSupplier; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; import org.elasticsearch.xpack.core.XPackPlugin; -import org.elasticsearch.xpack.spatial.aggregations.metrics.GeoShapeBoundsAggregator; -import org.elasticsearch.xpack.spatial.index.mapper.GeoShapeValuesSource; -import org.elasticsearch.xpack.spatial.index.mapper.GeoShapeValuesSourceType; import org.elasticsearch.xpack.spatial.index.mapper.GeoShapeWithDocValuesFieldMapper; import org.elasticsearch.xpack.spatial.index.mapper.PointFieldMapper; import org.elasticsearch.xpack.spatial.index.mapper.ShapeFieldMapper; import org.elasticsearch.xpack.spatial.index.query.ShapeQueryBuilder; import org.elasticsearch.xpack.spatial.ingest.CircleProcessor; +import org.elasticsearch.xpack.spatial.search.aggregations.metrics.GeoShapeBoundsAggregator; +import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSource; +import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType; import java.util.Collection; import java.util.Collections; @@ -67,7 +67,7 @@ public class SpatialPlugin extends GeoPlugin implements MapperPlugin, SearchPlug } public static void registerGeoShapeBoundsAggregator(ValuesSourceRegistry valuesSourceRegistry) { - valuesSourceRegistry.register(GeoBoundsAggregationBuilder.NAME, GeoShapeValuesSourceType.INSTANCE, + valuesSourceRegistry.register(GeoBoundsAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(), (GeoBoundsAggregatorSupplier) (name, aggregationContext, parent, valuesSource, wrapLongitude, metadata) -> new GeoShapeBoundsAggregator(name, aggregationContext, parent, (GeoShapeValuesSource) valuesSource, wrapLongitude, metadata)); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/CartesianPoint.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/common/CartesianPoint.java similarity index 99% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/CartesianPoint.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/common/CartesianPoint.java index e49803bfc1f..39d945d1d6c 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/CartesianPoint.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/common/CartesianPoint.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.common; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; @@ -19,6 +19,7 @@ import org.elasticsearch.geometry.Geometry; import org.elasticsearch.geometry.ShapeType; import org.elasticsearch.geometry.utils.StandardValidator; import org.elasticsearch.geometry.utils.WellKnownText; +import org.elasticsearch.xpack.spatial.index.mapper.PointFieldMapper; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/ShapeUtils.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/common/ShapeUtils.java similarity index 97% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/ShapeUtils.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/common/ShapeUtils.java index a5bf308e28f..65cd1aecdec 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/ShapeUtils.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/common/ShapeUtils.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.common; import org.elasticsearch.geometry.Circle; import org.elasticsearch.geometry.Line; @@ -11,11 +11,13 @@ import org.elasticsearch.geometry.Point; import org.elasticsearch.geometry.Polygon; import org.elasticsearch.geometry.Rectangle; - /** * Utility class that transforms Elasticsearch geometry objects to the Lucene representation */ public class ShapeUtils { + // no instance: + private ShapeUtils() { + } public static org.apache.lucene.geo.XYPolygon toLuceneXYPolygon(Polygon polygon) { org.apache.lucene.geo.XYPolygon[] holes = new org.apache.lucene.geo.XYPolygon[polygon.getNumberOfHoles()]; @@ -54,9 +56,6 @@ public class ShapeUtils { return new org.apache.lucene.geo.XYCircle((float) circle.getX(), (float) circle.getY(), (float) circle.getRadiusMeters()); } - private ShapeUtils() { - } - private static float[] doubleArrayToFloatArray(double[] array) { float[] result = new float[array.length]; for (int i = 0; i < array.length; ++i) { diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/AbstractAtomicGeoShapeShapeFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/AbstractAtomicGeoShapeShapeFieldData.java similarity index 96% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/AbstractAtomicGeoShapeShapeFieldData.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/AbstractAtomicGeoShapeShapeFieldData.java index fd5aa2dad05..a7a3f386e42 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/AbstractAtomicGeoShapeShapeFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/AbstractAtomicGeoShapeShapeFieldData.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.apache.lucene.util.Accountable; import org.elasticsearch.index.fielddata.ScriptDocValues; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/AbstractLatLonShapeDVIndexFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/AbstractLatLonShapeDVIndexFieldData.java similarity index 98% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/AbstractLatLonShapeDVIndexFieldData.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/AbstractLatLonShapeDVIndexFieldData.java index 2c861cfa2cc..30c698b9670 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/AbstractLatLonShapeDVIndexFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/AbstractLatLonShapeDVIndexFieldData.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.apache.lucene.index.DocValuesType; import org.apache.lucene.index.FieldInfo; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/CentroidCalculator.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/CentroidCalculator.java similarity index 99% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/CentroidCalculator.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/CentroidCalculator.java index 53ba4413279..40fefd11528 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/CentroidCalculator.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/CentroidCalculator.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.elasticsearch.common.geo.GeoUtils; import org.elasticsearch.geometry.Circle; @@ -23,7 +23,7 @@ import org.elasticsearch.search.aggregations.metrics.CompensatedSum; /** * This class keeps a running Kahan-sum of coordinates - * that are to be averaged in {@link TriangleTreeWriter} for use + * that are to be averaged in {@code TriangleTreeWriter} for use * as the centroid of a shape. */ public class CentroidCalculator { diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/CoordinateEncoder.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/CoordinateEncoder.java similarity index 84% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/CoordinateEncoder.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/CoordinateEncoder.java index 1d3fe6f60a9..646dae723be 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/CoordinateEncoder.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/CoordinateEncoder.java @@ -4,13 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; /** * Interface for classes that help encode double-valued spatial coordinates x/y to * their integer-encoded serialized form and decode them back */ -public interface CoordinateEncoder { +interface CoordinateEncoder { int encodeX(double x); int encodeY(double y); double decodeX(int x); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/DimensionalShapeType.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/DimensionalShapeType.java similarity index 95% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/DimensionalShapeType.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/DimensionalShapeType.java index 1cbcb5d012f..2985700805d 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/DimensionalShapeType.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/DimensionalShapeType.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.apache.lucene.store.ByteArrayDataInput; import org.apache.lucene.store.ByteBuffersDataOutput; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/Extent.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/Extent.java similarity index 98% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/Extent.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/Extent.java index 3e68caa8053..5903a5c6b56 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/Extent.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/Extent.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.apache.lucene.store.ByteArrayDataInput; import org.apache.lucene.store.ByteBuffersDataOutput; @@ -15,7 +15,7 @@ import java.util.Objects; /** * Object representing the extent of a geometry object within a {@link TriangleTreeWriter}. */ -public class Extent { +class Extent { public int top; public int bottom; @@ -31,7 +31,7 @@ public class Extent { private static final byte ALL_SET = 4; - public Extent() { + Extent() { this.top = Integer.MIN_VALUE; this.bottom = Integer.MAX_VALUE; this.negLeft = Integer.MAX_VALUE; @@ -40,7 +40,7 @@ public class Extent { this.posRight = Integer.MIN_VALUE; } - public Extent(int top, int bottom, int negLeft, int negRight, int posLeft, int posRight) { + Extent(int top, int bottom, int negLeft, int negRight, int posLeft, int posRight) { this.top = top; this.bottom = bottom; this.negLeft = negLeft; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoRelation.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoRelation.java similarity index 87% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoRelation.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoRelation.java index 7d2e5c19925..f75bef04dc5 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoRelation.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoRelation.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; /** * Enum for capturing relationships between a shape diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeCoordinateEncoder.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoShapeCoordinateEncoder.java similarity index 95% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeCoordinateEncoder.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoShapeCoordinateEncoder.java index 8780a23cf52..5ac40eef2ea 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeCoordinateEncoder.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoShapeCoordinateEncoder.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.apache.lucene.geo.GeoEncodingUtils; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/IndexGeoShapeFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/IndexGeoShapeFieldData.java similarity index 88% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/IndexGeoShapeFieldData.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/IndexGeoShapeFieldData.java index db4adb87fdd..feb43ed307d 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/IndexGeoShapeFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/IndexGeoShapeFieldData.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.elasticsearch.index.fielddata.IndexFieldData; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/LatLonShapeDVAtomicShapeFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/LatLonShapeDVAtomicShapeFieldData.java similarity index 92% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/LatLonShapeDVAtomicShapeFieldData.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/LatLonShapeDVAtomicShapeFieldData.java index d947e5f8965..2208619842f 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/LatLonShapeDVAtomicShapeFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/LatLonShapeDVAtomicShapeFieldData.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.apache.lucene.index.BinaryDocValues; import org.apache.lucene.index.DocValues; @@ -12,6 +12,7 @@ import org.apache.lucene.index.LeafReader; import org.apache.lucene.util.Accountable; import org.apache.lucene.util.BytesRef; import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType; import java.io.IOException; import java.util.Collection; @@ -62,7 +63,7 @@ final class LatLonShapeDVAtomicShapeFieldData extends AbstractAtomicGeoShapeShap @Override public ValuesSourceType valuesSourceType() { - return GeoShapeValuesSourceType.INSTANCE; + return GeoShapeValuesSourceType.instance(); } @Override diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/LeafGeoShapeFieldData.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/LeafGeoShapeFieldData.java similarity index 90% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/LeafGeoShapeFieldData.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/LeafGeoShapeFieldData.java index f9d4c67eb60..ec007b7b74c 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/LeafGeoShapeFieldData.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/LeafGeoShapeFieldData.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.elasticsearch.index.fielddata.LeafFieldData; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/MultiGeoShapeValues.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/MultiGeoShapeValues.java similarity index 95% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/MultiGeoShapeValues.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/MultiGeoShapeValues.java index fda5b60f218..b80ea071c15 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/MultiGeoShapeValues.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/MultiGeoShapeValues.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.apache.lucene.document.ShapeField; import org.apache.lucene.index.IndexableField; @@ -17,6 +17,7 @@ import org.elasticsearch.geometry.utils.GeographyValidator; import org.elasticsearch.geometry.utils.WellKnownText; import org.elasticsearch.index.mapper.GeoShapeIndexer; import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType; import java.io.IOException; import java.text.ParseException; @@ -40,7 +41,8 @@ import java.util.List; */ public abstract class MultiGeoShapeValues { - static MultiGeoShapeValues EMPTY = new MultiGeoShapeValues() { + public static MultiGeoShapeValues EMPTY = new MultiGeoShapeValues() { + private GeoShapeValuesSourceType DEFAULT_VALUES_SOURCE_TYPE = GeoShapeValuesSourceType.instance(); @Override public boolean advanceExact(int doc) { return false; @@ -53,7 +55,7 @@ public abstract class MultiGeoShapeValues { @Override public ValuesSourceType valuesSourceType() { - return GeoShapeValuesSourceType.INSTANCE; + return DEFAULT_VALUES_SOURCE_TYPE; } @Override diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/TriangleTreeReader.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/TriangleTreeReader.java similarity index 99% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/TriangleTreeReader.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/TriangleTreeReader.java index 5318585bc12..5673b6d3125 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/TriangleTreeReader.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/TriangleTreeReader.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.apache.lucene.store.ByteArrayDataInput; import org.apache.lucene.util.BytesRef; @@ -38,7 +38,7 @@ import static org.apache.lucene.geo.GeoUtils.orient; * ----------------------------------------- * ----------------------------------------- */ -public class TriangleTreeReader { +class TriangleTreeReader { private final ByteArrayDataInput input; private final CoordinateEncoder coordinateEncoder; private final Tile2D tile2D; @@ -46,7 +46,7 @@ public class TriangleTreeReader { private int treeOffset; private int docValueOffset; - public TriangleTreeReader(CoordinateEncoder coordinateEncoder) { + TriangleTreeReader(CoordinateEncoder coordinateEncoder) { this.coordinateEncoder = coordinateEncoder; this.tile2D = new Tile2D(); this.extent = new Extent(); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/TriangleTreeWriter.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/TriangleTreeWriter.java similarity index 99% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/TriangleTreeWriter.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/TriangleTreeWriter.java index 037941a8c63..7cf9ee28f27 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/TriangleTreeWriter.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/fielddata/TriangleTreeWriter.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.apache.lucene.document.ShapeField; import org.apache.lucene.store.ByteBuffersDataOutput; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/BinaryGeoShapeDocValuesField.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/BinaryGeoShapeDocValuesField.java index d2be10d41ae..ea648ff85f7 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/BinaryGeoShapeDocValuesField.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/BinaryGeoShapeDocValuesField.java @@ -11,6 +11,9 @@ import org.apache.lucene.store.ByteBuffersDataOutput; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.index.mapper.CustomDocValuesField; +import org.elasticsearch.xpack.spatial.index.fielddata.CentroidCalculator; +import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeCoordinateEncoder; +import org.elasticsearch.xpack.spatial.index.fielddata.TriangleTreeWriter; import java.io.IOException; import java.util.ArrayList; 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 5bb4ecf03e2..9acbc567934 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 @@ -36,6 +36,9 @@ import org.elasticsearch.index.mapper.TypeParsers; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.VectorGeoShapeQueryProcessor; import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.xpack.spatial.index.fielddata.AbstractLatLonShapeDVIndexFieldData; +import org.elasticsearch.xpack.spatial.index.fielddata.CentroidCalculator; +import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType; import java.io.IOException; import java.util.HashMap; @@ -173,7 +176,7 @@ public class GeoShapeWithDocValuesFieldMapper extends GeoShapeFieldMapper { @Override public ValuesSourceType getValuesSourceType() { - return GeoShapeValuesSourceType.INSTANCE; + return GeoShapeValuesSourceType.instance(); } @Override diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapper.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapper.java index 320e0e019cb..34d2fea9f4a 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapper.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapper.java @@ -32,6 +32,7 @@ import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardException; +import org.elasticsearch.xpack.spatial.common.CartesianPoint; import org.elasticsearch.xpack.spatial.index.query.ShapeQueryPointProcessor; import java.io.IOException; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/ShapeIndexer.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/ShapeIndexer.java index 7346a94c5f1..487aeb67035 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/ShapeIndexer.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/ShapeIndexer.java @@ -21,6 +21,7 @@ import org.elasticsearch.geometry.Polygon; import org.elasticsearch.geometry.Rectangle; import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper; import org.elasticsearch.index.mapper.ParseContext; +import org.elasticsearch.xpack.spatial.common.ShapeUtils; import java.util.ArrayList; import java.util.Arrays; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryPointProcessor.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryPointProcessor.java index b4b774a86dc..ecbe24582dc 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryPointProcessor.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryPointProcessor.java @@ -31,7 +31,7 @@ import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardException; import org.elasticsearch.xpack.spatial.index.mapper.PointFieldMapper; -import org.elasticsearch.xpack.spatial.index.mapper.ShapeUtils; +import org.elasticsearch.xpack.spatial.common.ShapeUtils; public class ShapeQueryPointProcessor implements AbstractSearchableGeometryFieldType.QueryProcessor { diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryProcessor.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryProcessor.java index b3f4d5fcdb0..65e8ea23d17 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryProcessor.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryProcessor.java @@ -28,7 +28,7 @@ import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardException; import org.elasticsearch.xpack.spatial.index.mapper.ShapeFieldMapper; -import org.elasticsearch.xpack.spatial.index.mapper.ShapeUtils; +import org.elasticsearch.xpack.spatial.common.ShapeUtils; import java.util.ArrayList; import java.util.List; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/aggregations/metrics/GeoShapeBoundsAggregator.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregator.java similarity index 96% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/aggregations/metrics/GeoShapeBoundsAggregator.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregator.java index 06270f2edfb..4a22f80784f 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/aggregations/metrics/GeoShapeBoundsAggregator.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregator.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.aggregations.metrics; +package org.elasticsearch.xpack.spatial.search.aggregations.metrics; import org.apache.lucene.index.LeafReaderContext; import org.elasticsearch.common.lease.Releasables; @@ -17,8 +17,8 @@ import org.elasticsearch.search.aggregations.LeafBucketCollectorBase; import org.elasticsearch.search.aggregations.metrics.InternalGeoBounds; import org.elasticsearch.search.aggregations.metrics.MetricsAggregator; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.xpack.spatial.index.mapper.GeoShapeValuesSource; -import org.elasticsearch.xpack.spatial.index.mapper.MultiGeoShapeValues; +import org.elasticsearch.xpack.spatial.index.fielddata.MultiGeoShapeValues; +import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSource; import java.io.IOException; import java.util.Map; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeValuesSource.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSource.java similarity index 90% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeValuesSource.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSource.java index 3604b8d908e..c1de13ffb44 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeValuesSource.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSource.java @@ -4,13 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.search.aggregations.support; import org.apache.lucene.index.LeafReaderContext; import org.elasticsearch.index.fielddata.DocValueBits; import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.xpack.spatial.index.fielddata.IndexGeoShapeFieldData; +import org.elasticsearch.xpack.spatial.index.fielddata.MultiGeoShapeValues; import java.io.IOException; diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeValuesSourceType.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSourceType.java similarity index 92% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeValuesSourceType.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSourceType.java index cd9412fe87f..5704b20c867 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeValuesSourceType.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/support/GeoShapeValuesSourceType.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.search.aggregations.support; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.util.BytesRef; @@ -19,13 +19,19 @@ import org.elasticsearch.search.aggregations.support.MissingValues; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceType; +import org.elasticsearch.xpack.spatial.index.fielddata.IndexGeoShapeFieldData; +import org.elasticsearch.xpack.spatial.index.fielddata.MultiGeoShapeValues; import java.io.IOException; import java.util.function.LongSupplier; public class GeoShapeValuesSourceType implements Writeable, ValuesSourceType { - public static GeoShapeValuesSourceType INSTANCE = new GeoShapeValuesSourceType(); + static GeoShapeValuesSourceType INSTANCE = new GeoShapeValuesSourceType(); + + public static GeoShapeValuesSourceType instance() { + return INSTANCE; + } @Override public ValuesSource getEmpty() { diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/CentroidCalculatorTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/CentroidCalculatorTests.java similarity index 98% rename from x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/CentroidCalculatorTests.java rename to x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/CentroidCalculatorTests.java index d6810377ce9..917322d3650 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/CentroidCalculatorTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/CentroidCalculatorTests.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.elasticsearch.common.collect.List; import org.elasticsearch.common.geo.GeoUtils; @@ -25,9 +25,9 @@ import org.elasticsearch.test.ESTestCase; import java.util.ArrayList; import java.util.Collections; -import static org.elasticsearch.xpack.spatial.index.mapper.DimensionalShapeType.LINE; -import static org.elasticsearch.xpack.spatial.index.mapper.DimensionalShapeType.POINT; -import static org.elasticsearch.xpack.spatial.index.mapper.DimensionalShapeType.POLYGON; +import static org.elasticsearch.xpack.spatial.index.fielddata.DimensionalShapeType.LINE; +import static org.elasticsearch.xpack.spatial.index.fielddata.DimensionalShapeType.POINT; +import static org.elasticsearch.xpack.spatial.index.fielddata.DimensionalShapeType.POLYGON; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.closeTo; import static org.hamcrest.Matchers.equalTo; diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeCoordinateEncoderTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoShapeCoordinateEncoderTests.java similarity index 91% rename from x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeCoordinateEncoderTests.java rename to x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoShapeCoordinateEncoderTests.java index 821ffd97e7d..f180c08ac55 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeCoordinateEncoderTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/GeoShapeCoordinateEncoderTests.java @@ -4,12 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.apache.lucene.geo.GeoEncodingUtils; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeCoordinateEncoder; -import static org.elasticsearch.xpack.spatial.index.mapper.GeoShapeCoordinateEncoder.INSTANCE; +import static org.elasticsearch.xpack.spatial.index.fielddata.GeoShapeCoordinateEncoder.INSTANCE; import static org.hamcrest.Matchers.closeTo; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.equalTo; diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/TestCoordinateEncoder.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/TestCoordinateEncoder.java similarity index 93% rename from x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/TestCoordinateEncoder.java rename to x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/TestCoordinateEncoder.java index e4f0df2f000..7c4a43776f6 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/TestCoordinateEncoder.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/TestCoordinateEncoder.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; /** * {@link CoordinateEncoder} used for tests that is an identity-encoder-decoder diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/TriangleTreeTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/TriangleTreeTests.java similarity index 94% rename from x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/TriangleTreeTests.java rename to x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/TriangleTreeTests.java index b4017988a94..a8ff53bc57b 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/TriangleTreeTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/TriangleTreeTests.java @@ -4,9 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.index.mapper; +package org.elasticsearch.xpack.spatial.index.fielddata; import org.elasticsearch.common.collect.List; +import org.apache.lucene.document.ShapeField; +import org.apache.lucene.store.ByteBuffersDataOutput; +import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.CheckedBiFunction; import org.elasticsearch.geo.GeometryTestUtils; import org.elasticsearch.geometry.Circle; @@ -24,6 +27,7 @@ import org.elasticsearch.geometry.Rectangle; import org.elasticsearch.geometry.ShapeType; import org.elasticsearch.index.mapper.GeoShapeIndexer; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.spatial.util.GeoTestUtils; import java.io.IOException; import java.util.ArrayList; @@ -31,8 +35,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.function.Function; -import static org.elasticsearch.xpack.spatial.util.GeoTestUtils.assertRelation; -import static org.elasticsearch.xpack.spatial.util.GeoTestUtils.triangleTreeReader; import static org.elasticsearch.geo.GeometryTestUtils.randomLine; import static org.elasticsearch.geo.GeometryTestUtils.randomMultiLine; import static org.elasticsearch.geo.GeometryTestUtils.randomMultiPoint; @@ -416,4 +418,19 @@ public class TriangleTreeTests extends ESTestCase { } }); } + + static void assertRelation(GeoRelation expectedRelation, TriangleTreeReader reader, Extent extent) throws IOException { + GeoRelation actualRelation = reader.relateTile(extent.minX(), extent.minY(), extent.maxX(), extent.maxY()); + assertThat(actualRelation, equalTo(expectedRelation)); + } + + static TriangleTreeReader triangleTreeReader(Geometry geometry, CoordinateEncoder encoder) throws IOException { + ShapeField.DecodedTriangle[] triangles = GeoTestUtils.toDecodedTriangles(geometry); + TriangleTreeWriter writer = new TriangleTreeWriter(Arrays.asList(triangles), encoder, new CentroidCalculator(geometry)); + ByteBuffersDataOutput output = new ByteBuffersDataOutput(); + writer.writeTo(output); + TriangleTreeReader reader = new TriangleTreeReader(encoder); + reader.reset(new BytesRef(output.toArrayCopy(), 0, Math.toIntExact(output.size()))); + return reader; + } } diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapperTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapperTests.java index cd04672e650..1209609391a 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapperTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapperTests.java @@ -16,6 +16,7 @@ import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.Mapper; import org.elasticsearch.index.mapper.ParsedDocument; import org.elasticsearch.index.mapper.SourceToParse; +import org.elasticsearch.xpack.spatial.common.CartesianPoint; import org.hamcrest.CoreMatchers; import java.io.IOException; diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/aggregations/metrics/GeoShapeBoundsAggregatorTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregatorTests.java similarity index 97% rename from x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/aggregations/metrics/GeoShapeBoundsAggregatorTests.java rename to x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregatorTests.java index 9ffb48e8e6c..d666f3f198a 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/aggregations/metrics/GeoShapeBoundsAggregatorTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/GeoShapeBoundsAggregatorTests.java @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.spatial.aggregations.metrics; +package org.elasticsearch.xpack.spatial.search.aggregations.metrics; import org.apache.lucene.document.Document; import org.apache.lucene.document.LatLonDocValuesField; @@ -28,10 +28,10 @@ import org.elasticsearch.search.aggregations.support.AggregationInspectionHelper import org.elasticsearch.search.aggregations.support.CoreValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.xpack.spatial.SpatialPlugin; +import org.elasticsearch.xpack.spatial.index.fielddata.CentroidCalculator; import org.elasticsearch.xpack.spatial.index.mapper.BinaryGeoShapeDocValuesField; -import org.elasticsearch.xpack.spatial.index.mapper.CentroidCalculator; -import org.elasticsearch.xpack.spatial.index.mapper.GeoShapeValuesSourceType; import org.elasticsearch.xpack.spatial.index.mapper.GeoShapeWithDocValuesFieldMapper; +import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType; import org.elasticsearch.xpack.spatial.util.GeoTestUtils; import org.junit.BeforeClass; @@ -227,6 +227,6 @@ public class GeoShapeBoundsAggregatorTests extends AggregatorTestCase { @Override protected List getSupportedValuesSourceTypes() { - return org.elasticsearch.common.collect.List.of(CoreValuesSourceType.GEOPOINT, GeoShapeValuesSourceType.INSTANCE); + return org.elasticsearch.common.collect.List.of(CoreValuesSourceType.GEOPOINT, GeoShapeValuesSourceType.instance()); } } diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/util/GeoTestUtils.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/util/GeoTestUtils.java index 0bd7117524b..a903d5b1186 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/util/GeoTestUtils.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/util/GeoTestUtils.java @@ -9,7 +9,6 @@ package org.elasticsearch.xpack.spatial.util; import org.apache.lucene.document.ShapeField; import org.apache.lucene.geo.GeoEncodingUtils; import org.apache.lucene.index.IndexableField; -import org.apache.lucene.store.ByteBuffersDataOutput; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -25,27 +24,12 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.geometry.Geometry; import org.elasticsearch.index.mapper.GeoShapeIndexer; -import org.elasticsearch.xpack.spatial.index.mapper.CentroidCalculator; -import org.elasticsearch.xpack.spatial.index.mapper.CoordinateEncoder; -import org.elasticsearch.xpack.spatial.index.mapper.Extent; -import org.elasticsearch.xpack.spatial.index.mapper.GeoRelation; -import org.elasticsearch.xpack.spatial.index.mapper.TriangleTreeReader; -import org.elasticsearch.xpack.spatial.index.mapper.TriangleTreeWriter; import java.io.IOException; -import java.util.Arrays; import java.util.List; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - public class GeoTestUtils { - public static void assertRelation(GeoRelation expectedRelation, TriangleTreeReader reader, Extent extent) throws IOException { - GeoRelation actualRelation = reader.relateTile(extent.minX(), extent.minY(), extent.maxX(), extent.maxY()); - assertThat(actualRelation, equalTo(expectedRelation)); - } - public static ShapeField.DecodedTriangle[] toDecodedTriangles(Geometry geometry) throws IOException { GeoShapeIndexer indexer = new GeoShapeIndexer(true, "test"); geometry = indexer.prepareForIndexing(geometry); @@ -61,16 +45,6 @@ public class GeoTestUtils { return triangles; } - public static TriangleTreeReader triangleTreeReader(Geometry geometry, CoordinateEncoder encoder) throws IOException { - ShapeField.DecodedTriangle[] triangles = toDecodedTriangles(geometry); - TriangleTreeWriter writer = new TriangleTreeWriter(Arrays.asList(triangles), encoder, new CentroidCalculator(geometry)); - ByteBuffersDataOutput output = new ByteBuffersDataOutput(); - writer.writeTo(output); - TriangleTreeReader reader = new TriangleTreeReader(encoder); - reader.reset(new BytesRef(output.toArrayCopy(), 0, Math.toIntExact(output.size()))); - return reader; - } - public static double encodeDecodeLat(double lat) { return GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lat)); }