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.
This commit is contained in:
Nick Knize 2020-04-23 15:32:23 -05:00 committed by GitHub
parent 46be9959a0
commit 96a02089c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 95 additions and 83 deletions

View File

@ -16,14 +16,14 @@ import org.elasticsearch.search.aggregations.metrics.GeoBoundsAggregationBuilder
import org.elasticsearch.search.aggregations.metrics.GeoBoundsAggregatorSupplier; import org.elasticsearch.search.aggregations.metrics.GeoBoundsAggregatorSupplier;
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry; import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
import org.elasticsearch.xpack.core.XPackPlugin; 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.GeoShapeWithDocValuesFieldMapper;
import org.elasticsearch.xpack.spatial.index.mapper.PointFieldMapper; import org.elasticsearch.xpack.spatial.index.mapper.PointFieldMapper;
import org.elasticsearch.xpack.spatial.index.mapper.ShapeFieldMapper; import org.elasticsearch.xpack.spatial.index.mapper.ShapeFieldMapper;
import org.elasticsearch.xpack.spatial.index.query.ShapeQueryBuilder; import org.elasticsearch.xpack.spatial.index.query.ShapeQueryBuilder;
import org.elasticsearch.xpack.spatial.ingest.CircleProcessor; 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.Collection;
import java.util.Collections; import java.util.Collections;
@ -67,7 +67,7 @@ public class SpatialPlugin extends GeoPlugin implements MapperPlugin, SearchPlug
} }
public static void registerGeoShapeBoundsAggregator(ValuesSourceRegistry valuesSourceRegistry) { 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) (GeoBoundsAggregatorSupplier) (name, aggregationContext, parent, valuesSource, wrapLongitude, metadata)
-> new GeoShapeBoundsAggregator(name, aggregationContext, parent, (GeoShapeValuesSource) valuesSource, -> new GeoShapeBoundsAggregator(name, aggregationContext, parent, (GeoShapeValuesSource) valuesSource,
wrapLongitude, metadata)); wrapLongitude, metadata));

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
@ -19,6 +19,7 @@ import org.elasticsearch.geometry.Geometry;
import org.elasticsearch.geometry.ShapeType; import org.elasticsearch.geometry.ShapeType;
import org.elasticsearch.geometry.utils.StandardValidator; import org.elasticsearch.geometry.utils.StandardValidator;
import org.elasticsearch.geometry.utils.WellKnownText; import org.elasticsearch.geometry.utils.WellKnownText;
import org.elasticsearch.xpack.spatial.index.mapper.PointFieldMapper;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with 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.Circle;
import org.elasticsearch.geometry.Line; import org.elasticsearch.geometry.Line;
@ -11,11 +11,13 @@ import org.elasticsearch.geometry.Point;
import org.elasticsearch.geometry.Polygon; import org.elasticsearch.geometry.Polygon;
import org.elasticsearch.geometry.Rectangle; import org.elasticsearch.geometry.Rectangle;
/** /**
* Utility class that transforms Elasticsearch geometry objects to the Lucene representation * Utility class that transforms Elasticsearch geometry objects to the Lucene representation
*/ */
public class ShapeUtils { public class ShapeUtils {
// no instance:
private ShapeUtils() {
}
public static org.apache.lucene.geo.XYPolygon toLuceneXYPolygon(Polygon polygon) { public static org.apache.lucene.geo.XYPolygon toLuceneXYPolygon(Polygon polygon) {
org.apache.lucene.geo.XYPolygon[] holes = new org.apache.lucene.geo.XYPolygon[polygon.getNumberOfHoles()]; 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()); return new org.apache.lucene.geo.XYCircle((float) circle.getX(), (float) circle.getY(), (float) circle.getRadiusMeters());
} }
private ShapeUtils() {
}
private static float[] doubleArrayToFloatArray(double[] array) { private static float[] doubleArrayToFloatArray(double[] array) {
float[] result = new float[array.length]; float[] result = new float[array.length];
for (int i = 0; i < array.length; ++i) { for (int i = 0; i < array.length; ++i) {

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.apache.lucene.util.Accountable; import org.apache.lucene.util.Accountable;
import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.index.fielddata.ScriptDocValues;

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.apache.lucene.index.DocValuesType; import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfo;

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.elasticsearch.common.geo.GeoUtils; import org.elasticsearch.common.geo.GeoUtils;
import org.elasticsearch.geometry.Circle; 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 * 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. * as the centroid of a shape.
*/ */
public class CentroidCalculator { public class CentroidCalculator {

View File

@ -4,13 +4,13 @@
* you may not use this file except in compliance with 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.index.fielddata;
/** /**
* Interface for classes that help encode double-valued spatial coordinates x/y to * Interface for classes that help encode double-valued spatial coordinates x/y to
* their integer-encoded serialized form and decode them back * their integer-encoded serialized form and decode them back
*/ */
public interface CoordinateEncoder { interface CoordinateEncoder {
int encodeX(double x); int encodeX(double x);
int encodeY(double y); int encodeY(double y);
double decodeX(int x); double decodeX(int x);

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.apache.lucene.store.ByteArrayDataInput; import org.apache.lucene.store.ByteArrayDataInput;
import org.apache.lucene.store.ByteBuffersDataOutput; import org.apache.lucene.store.ByteBuffersDataOutput;

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.apache.lucene.store.ByteArrayDataInput; import org.apache.lucene.store.ByteArrayDataInput;
import org.apache.lucene.store.ByteBuffersDataOutput; 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}. * Object representing the extent of a geometry object within a {@link TriangleTreeWriter}.
*/ */
public class Extent { class Extent {
public int top; public int top;
public int bottom; public int bottom;
@ -31,7 +31,7 @@ public class Extent {
private static final byte ALL_SET = 4; private static final byte ALL_SET = 4;
public Extent() { Extent() {
this.top = Integer.MIN_VALUE; this.top = Integer.MIN_VALUE;
this.bottom = Integer.MAX_VALUE; this.bottom = Integer.MAX_VALUE;
this.negLeft = Integer.MAX_VALUE; this.negLeft = Integer.MAX_VALUE;
@ -40,7 +40,7 @@ public class Extent {
this.posRight = Integer.MIN_VALUE; 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.top = top;
this.bottom = bottom; this.bottom = bottom;
this.negLeft = negLeft; this.negLeft = negLeft;

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
/** /**
* Enum for capturing relationships between a shape * Enum for capturing relationships between a shape

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.apache.lucene.geo.GeoEncodingUtils; import org.apache.lucene.geo.GeoEncodingUtils;

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexFieldData;

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.apache.lucene.index.BinaryDocValues; import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.DocValues; 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.Accountable;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
@ -62,7 +63,7 @@ final class LatLonShapeDVAtomicShapeFieldData extends AbstractAtomicGeoShapeShap
@Override @Override
public ValuesSourceType valuesSourceType() { public ValuesSourceType valuesSourceType() {
return GeoShapeValuesSourceType.INSTANCE; return GeoShapeValuesSourceType.instance();
} }
@Override @Override

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.elasticsearch.index.fielddata.LeafFieldData; import org.elasticsearch.index.fielddata.LeafFieldData;

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.apache.lucene.document.ShapeField; import org.apache.lucene.document.ShapeField;
import org.apache.lucene.index.IndexableField; 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.geometry.utils.WellKnownText;
import org.elasticsearch.index.mapper.GeoShapeIndexer; import org.elasticsearch.index.mapper.GeoShapeIndexer;
import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
@ -40,7 +41,8 @@ import java.util.List;
*/ */
public abstract class MultiGeoShapeValues { public abstract class MultiGeoShapeValues {
static MultiGeoShapeValues EMPTY = new MultiGeoShapeValues() { public static MultiGeoShapeValues EMPTY = new MultiGeoShapeValues() {
private GeoShapeValuesSourceType DEFAULT_VALUES_SOURCE_TYPE = GeoShapeValuesSourceType.instance();
@Override @Override
public boolean advanceExact(int doc) { public boolean advanceExact(int doc) {
return false; return false;
@ -53,7 +55,7 @@ public abstract class MultiGeoShapeValues {
@Override @Override
public ValuesSourceType valuesSourceType() { public ValuesSourceType valuesSourceType() {
return GeoShapeValuesSourceType.INSTANCE; return DEFAULT_VALUES_SOURCE_TYPE;
} }
@Override @Override

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.apache.lucene.store.ByteArrayDataInput; import org.apache.lucene.store.ByteArrayDataInput;
import org.apache.lucene.util.BytesRef; 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 ByteArrayDataInput input;
private final CoordinateEncoder coordinateEncoder; private final CoordinateEncoder coordinateEncoder;
private final Tile2D tile2D; private final Tile2D tile2D;
@ -46,7 +46,7 @@ public class TriangleTreeReader {
private int treeOffset; private int treeOffset;
private int docValueOffset; private int docValueOffset;
public TriangleTreeReader(CoordinateEncoder coordinateEncoder) { TriangleTreeReader(CoordinateEncoder coordinateEncoder) {
this.coordinateEncoder = coordinateEncoder; this.coordinateEncoder = coordinateEncoder;
this.tile2D = new Tile2D(); this.tile2D = new Tile2D();
this.extent = new Extent(); this.extent = new Extent();

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.apache.lucene.document.ShapeField; import org.apache.lucene.document.ShapeField;
import org.apache.lucene.store.ByteBuffersDataOutput; import org.apache.lucene.store.ByteBuffersDataOutput;

View File

@ -11,6 +11,9 @@ import org.apache.lucene.store.ByteBuffersDataOutput;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.index.mapper.CustomDocValuesField; 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.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -36,6 +36,9 @@ import org.elasticsearch.index.mapper.TypeParsers;
import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.VectorGeoShapeQueryProcessor; import org.elasticsearch.index.query.VectorGeoShapeQueryProcessor;
import org.elasticsearch.search.aggregations.support.ValuesSourceType; 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.io.IOException;
import java.util.HashMap; import java.util.HashMap;
@ -173,7 +176,7 @@ public class GeoShapeWithDocValuesFieldMapper extends GeoShapeFieldMapper {
@Override @Override
public ValuesSourceType getValuesSourceType() { public ValuesSourceType getValuesSourceType() {
return GeoShapeValuesSourceType.INSTANCE; return GeoShapeValuesSourceType.instance();
} }
@Override @Override

View File

@ -32,6 +32,7 @@ import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.QueryShardException; import org.elasticsearch.index.query.QueryShardException;
import org.elasticsearch.xpack.spatial.common.CartesianPoint;
import org.elasticsearch.xpack.spatial.index.query.ShapeQueryPointProcessor; import org.elasticsearch.xpack.spatial.index.query.ShapeQueryPointProcessor;
import java.io.IOException; import java.io.IOException;

View File

@ -21,6 +21,7 @@ import org.elasticsearch.geometry.Polygon;
import org.elasticsearch.geometry.Rectangle; import org.elasticsearch.geometry.Rectangle;
import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper; import org.elasticsearch.index.mapper.AbstractGeometryFieldMapper;
import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.xpack.spatial.common.ShapeUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;

View File

@ -31,7 +31,7 @@ import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.QueryShardException; import org.elasticsearch.index.query.QueryShardException;
import org.elasticsearch.xpack.spatial.index.mapper.PointFieldMapper; 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 { public class ShapeQueryPointProcessor implements AbstractSearchableGeometryFieldType.QueryProcessor {

View File

@ -28,7 +28,7 @@ import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.index.query.QueryShardException; import org.elasticsearch.index.query.QueryShardException;
import org.elasticsearch.xpack.spatial.index.mapper.ShapeFieldMapper; 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.ArrayList;
import java.util.List; import java.util.List;

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License. * 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.apache.lucene.index.LeafReaderContext;
import org.elasticsearch.common.lease.Releasables; 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.InternalGeoBounds;
import org.elasticsearch.search.aggregations.metrics.MetricsAggregator; import org.elasticsearch.search.aggregations.metrics.MetricsAggregator;
import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.xpack.spatial.index.mapper.GeoShapeValuesSource; import org.elasticsearch.xpack.spatial.index.fielddata.MultiGeoShapeValues;
import org.elasticsearch.xpack.spatial.index.mapper.MultiGeoShapeValues; import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSource;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;

View File

@ -4,13 +4,15 @@
* you may not use this file except in compliance with 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.search.aggregations.support;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.elasticsearch.index.fielddata.DocValueBits; import org.elasticsearch.index.fielddata.DocValueBits;
import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.FieldData;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues; import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.search.aggregations.support.ValuesSource; 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; import java.io.IOException;

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.search.aggregations.support;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.util.BytesRef; 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.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceType; 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.io.IOException;
import java.util.function.LongSupplier; import java.util.function.LongSupplier;
public class GeoShapeValuesSourceType implements Writeable, ValuesSourceType { public class GeoShapeValuesSourceType implements Writeable, ValuesSourceType {
public static GeoShapeValuesSourceType INSTANCE = new GeoShapeValuesSourceType(); static GeoShapeValuesSourceType INSTANCE = new GeoShapeValuesSourceType();
public static GeoShapeValuesSourceType instance() {
return INSTANCE;
}
@Override @Override
public ValuesSource getEmpty() { public ValuesSource getEmpty() {

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.elasticsearch.common.collect.List; import org.elasticsearch.common.collect.List;
import org.elasticsearch.common.geo.GeoUtils; import org.elasticsearch.common.geo.GeoUtils;
@ -25,9 +25,9 @@ import org.elasticsearch.test.ESTestCase;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import static org.elasticsearch.xpack.spatial.index.mapper.DimensionalShapeType.LINE; import static org.elasticsearch.xpack.spatial.index.fielddata.DimensionalShapeType.LINE;
import static org.elasticsearch.xpack.spatial.index.mapper.DimensionalShapeType.POINT; import static org.elasticsearch.xpack.spatial.index.fielddata.DimensionalShapeType.POINT;
import static org.elasticsearch.xpack.spatial.index.mapper.DimensionalShapeType.POLYGON; import static org.elasticsearch.xpack.spatial.index.fielddata.DimensionalShapeType.POLYGON;
import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.closeTo; import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;

View File

@ -4,12 +4,13 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.apache.lucene.geo.GeoEncodingUtils; import org.apache.lucene.geo.GeoEncodingUtils;
import org.elasticsearch.test.ESTestCase; 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.closeTo;
import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with 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.index.fielddata;
/** /**
* {@link CoordinateEncoder} used for tests that is an identity-encoder-decoder * {@link CoordinateEncoder} used for tests that is an identity-encoder-decoder

View File

@ -4,9 +4,12 @@
* you may not use this file except in compliance with 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.index.fielddata;
import org.elasticsearch.common.collect.List; 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.common.CheckedBiFunction;
import org.elasticsearch.geo.GeometryTestUtils; import org.elasticsearch.geo.GeometryTestUtils;
import org.elasticsearch.geometry.Circle; import org.elasticsearch.geometry.Circle;
@ -24,6 +27,7 @@ import org.elasticsearch.geometry.Rectangle;
import org.elasticsearch.geometry.ShapeType; import org.elasticsearch.geometry.ShapeType;
import org.elasticsearch.index.mapper.GeoShapeIndexer; import org.elasticsearch.index.mapper.GeoShapeIndexer;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.spatial.util.GeoTestUtils;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,8 +35,6 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.function.Function; 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.randomLine;
import static org.elasticsearch.geo.GeometryTestUtils.randomMultiLine; import static org.elasticsearch.geo.GeometryTestUtils.randomMultiLine;
import static org.elasticsearch.geo.GeometryTestUtils.randomMultiPoint; 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;
}
} }

View File

@ -16,6 +16,7 @@ import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.Mapper; import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.ParsedDocument; import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse; import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.xpack.spatial.common.CartesianPoint;
import org.hamcrest.CoreMatchers; import org.hamcrest.CoreMatchers;
import java.io.IOException; import java.io.IOException;

View File

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License. * 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.Document;
import org.apache.lucene.document.LatLonDocValuesField; 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.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceType; import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.xpack.spatial.SpatialPlugin; 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.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.index.mapper.GeoShapeWithDocValuesFieldMapper;
import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType;
import org.elasticsearch.xpack.spatial.util.GeoTestUtils; import org.elasticsearch.xpack.spatial.util.GeoTestUtils;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -227,6 +227,6 @@ public class GeoShapeBoundsAggregatorTests extends AggregatorTestCase {
@Override @Override
protected List<ValuesSourceType> getSupportedValuesSourceTypes() { protected List<ValuesSourceType> getSupportedValuesSourceTypes() {
return org.elasticsearch.common.collect.List.of(CoreValuesSourceType.GEOPOINT, GeoShapeValuesSourceType.INSTANCE); return org.elasticsearch.common.collect.List.of(CoreValuesSourceType.GEOPOINT, GeoShapeValuesSourceType.instance());
} }
} }

View File

@ -9,7 +9,6 @@ package org.elasticsearch.xpack.spatial.util;
import org.apache.lucene.document.ShapeField; import org.apache.lucene.document.ShapeField;
import org.apache.lucene.geo.GeoEncodingUtils; import org.apache.lucene.geo.GeoEncodingUtils;
import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.IndexableField;
import org.apache.lucene.store.ByteBuffersDataOutput;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference; 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.common.xcontent.XContentType;
import org.elasticsearch.geometry.Geometry; import org.elasticsearch.geometry.Geometry;
import org.elasticsearch.index.mapper.GeoShapeIndexer; 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.io.IOException;
import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
public class GeoTestUtils { 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 { public static ShapeField.DecodedTriangle[] toDecodedTriangles(Geometry geometry) throws IOException {
GeoShapeIndexer indexer = new GeoShapeIndexer(true, "test"); GeoShapeIndexer indexer = new GeoShapeIndexer(true, "test");
geometry = indexer.prepareForIndexing(geometry); geometry = indexer.prepareForIndexing(geometry);
@ -61,16 +45,6 @@ public class GeoTestUtils {
return triangles; 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) { public static double encodeDecodeLat(double lat) {
return GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lat)); return GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lat));
} }