Quellcode durchsuchen

Change visibility of GeoGrid base class and methods from package private to protected (#81643)

This change should help implemening new GeoGrid aggregations over geo_points in a different module.
Ignacio Vera vor 3 Jahren
Ursprung
Commit
b011c1701c

+ 2 - 2
server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/CellValues.java

@@ -17,7 +17,7 @@ import java.io.IOException;
  * the geo-doc-values. Class must encode the values and then
  * sort them in order to account for the cells correctly.
  */
-abstract class CellValues extends AbstractSortingNumericDocValues {
+public abstract class CellValues extends AbstractSortingNumericDocValues {
     private MultiGeoPointValues geoValues;
     protected int precision;
 
@@ -51,5 +51,5 @@ abstract class CellValues extends AbstractSortingNumericDocValues {
      * @param valuesIdx the index into <code>values</code> to set
      * @return          valuesIdx + 1 if value was set, valuesIdx otherwise.
      */
-    abstract int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx);
+    protected abstract int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx);
 }

+ 3 - 3
server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregator.java

@@ -38,7 +38,7 @@ public abstract class GeoGridAggregator<T extends InternalGeoGrid<?>> extends Bu
     protected final ValuesSource.Numeric valuesSource;
     protected final LongKeyedBucketOrds bucketOrds;
 
-    GeoGridAggregator(
+    protected GeoGridAggregator(
         String name,
         AggregatorFactories factories,
         ValuesSource.Numeric valuesSource,
@@ -92,14 +92,14 @@ public abstract class GeoGridAggregator<T extends InternalGeoGrid<?>> extends Bu
         };
     }
 
-    abstract T buildAggregation(String name, int requiredSize, List<InternalGeoGridBucket> buckets, Map<String, Object> metadata);
+    protected abstract T buildAggregation(String name, int requiredSize, List<InternalGeoGridBucket> buckets, Map<String, Object> metadata);
 
     /**
      * This method is used to return a re-usable instance of the bucket when building
      * the aggregation.
      * @return a new {@link InternalGeoGridBucket} implementation with empty parameters
      */
-    abstract InternalGeoGridBucket newEmptyBucket();
+    protected abstract InternalGeoGridBucket newEmptyBucket();
 
     @Override
     public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws IOException {

+ 2 - 2
server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashCellIdSource.java

@@ -65,7 +65,7 @@ public class GeoHashCellIdSource extends ValuesSource.Numeric {
         }
 
         @Override
-        int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) {
+        protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) {
             values[valuesIdx] = Geohash.longEncode(target.getLon(), target.getLat(), precision);
             return valuesIdx + 1;
         }
@@ -83,7 +83,7 @@ public class GeoHashCellIdSource extends ValuesSource.Numeric {
         }
 
         @Override
-        int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) {
+        protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) {
             final String hash = Geohash.stringEncode(target.getLon(), target.getLat(), precision);
             if (validHash(hash)) {
                 values[valuesIdx] = Geohash.longEncode(hash);

+ 7 - 2
server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregator.java

@@ -38,7 +38,12 @@ public class GeoHashGridAggregator extends GeoGridAggregator<InternalGeoHashGrid
     }
 
     @Override
-    InternalGeoHashGrid buildAggregation(String name, int requiredSize, List<InternalGeoGridBucket> buckets, Map<String, Object> metadata) {
+    protected InternalGeoHashGrid buildAggregation(
+        String name,
+        int requiredSize,
+        List<InternalGeoGridBucket> buckets,
+        Map<String, Object> metadata
+    ) {
         return new InternalGeoHashGrid(name, requiredSize, buckets, metadata);
     }
 
@@ -47,7 +52,7 @@ public class GeoHashGridAggregator extends GeoGridAggregator<InternalGeoHashGrid
         return new InternalGeoHashGrid(name, requiredSize, Collections.emptyList(), metadata());
     }
 
-    InternalGeoGridBucket newEmptyBucket() {
+    protected InternalGeoGridBucket newEmptyBucket() {
         return new InternalGeoHashGridBucket(0, 0, null);
     }
 }

+ 2 - 2
server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileCellIdSource.java

@@ -64,7 +64,7 @@ public class GeoTileCellIdSource extends ValuesSource.Numeric {
         }
 
         @Override
-        int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) {
+        protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) {
             values[valuesIdx] = GeoTileUtils.longEncode(target.getLon(), target.getLat(), precision);
             return valuesIdx + 1;
         }
@@ -97,7 +97,7 @@ public class GeoTileCellIdSource extends ValuesSource.Numeric {
         }
 
         @Override
-        int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) {
+        protected int advanceValue(org.elasticsearch.common.geo.GeoPoint target, int valuesIdx) {
             final int x = GeoTileUtils.getXTile(target.getLon(), this.tiles);
             final int y = GeoTileUtils.getYTile(target.getLat(), this.tiles);
             if (validTile(x, y)) {

+ 7 - 2
server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoTileGridAggregator.java

@@ -39,7 +39,12 @@ public class GeoTileGridAggregator extends GeoGridAggregator<InternalGeoTileGrid
     }
 
     @Override
-    InternalGeoTileGrid buildAggregation(String name, int requiredSize, List<InternalGeoGridBucket> buckets, Map<String, Object> metadata) {
+    protected InternalGeoTileGrid buildAggregation(
+        String name,
+        int requiredSize,
+        List<InternalGeoGridBucket> buckets,
+        Map<String, Object> metadata
+    ) {
         return new InternalGeoTileGrid(name, requiredSize, buckets, metadata);
     }
 
@@ -48,7 +53,7 @@ public class GeoTileGridAggregator extends GeoGridAggregator<InternalGeoTileGrid
         return new InternalGeoTileGrid(name, requiredSize, Collections.emptyList(), metadata());
     }
 
-    InternalGeoGridBucket newEmptyBucket() {
+    protected InternalGeoGridBucket newEmptyBucket() {
         return new InternalGeoTileGridBucket(0, 0, null);
     }
 }

+ 9 - 4
server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoGrid.java

@@ -38,13 +38,13 @@ public abstract class InternalGeoGrid<B extends InternalGeoGridBucket> extends I
     protected final int requiredSize;
     protected final List<InternalGeoGridBucket> buckets;
 
-    InternalGeoGrid(String name, int requiredSize, List<InternalGeoGridBucket> buckets, Map<String, Object> metadata) {
+    protected InternalGeoGrid(String name, int requiredSize, List<InternalGeoGridBucket> buckets, Map<String, Object> metadata) {
         super(name, metadata);
         this.requiredSize = requiredSize;
         this.buckets = buckets;
     }
 
-    abstract Writeable.Reader<B> getBucketReader();
+    protected abstract Writeable.Reader<B> getBucketReader();
 
     /**
      * Read from a stream.
@@ -62,7 +62,12 @@ public abstract class InternalGeoGrid<B extends InternalGeoGridBucket> extends I
         out.writeList(buckets);
     }
 
-    abstract InternalGeoGrid<B> create(String name, int requiredSize, List<InternalGeoGridBucket> buckets, Map<String, Object> metadata);
+    protected abstract InternalGeoGrid<B> create(
+        String name,
+        int requiredSize,
+        List<InternalGeoGridBucket> buckets,
+        Map<String, Object> metadata
+    );
 
     @Override
     public List<InternalGeoGridBucket> getBuckets() {
@@ -117,7 +122,7 @@ public abstract class InternalGeoGrid<B extends InternalGeoGridBucket> extends I
         return createBucket(buckets.get(0).hashAsLong, docCount, aggs);
     }
 
-    abstract B createBucket(long hashAsLong, long docCount, InternalAggregations aggregations);
+    protected abstract B createBucket(long hashAsLong, long docCount, InternalAggregations aggregations);
 
     @Override
     public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {

+ 1 - 1
server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoGridBucket.java

@@ -51,7 +51,7 @@ public abstract class InternalGeoGridBucket extends InternalMultiBucketAggregati
         aggregations.writeTo(out);
     }
 
-    long hashAsLong() {
+    protected long hashAsLong() {
         return hashAsLong;
     }
 

+ 3 - 3
server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGrid.java

@@ -40,7 +40,7 @@ public class InternalGeoHashGrid extends InternalGeoGrid<InternalGeoHashGridBuck
     }
 
     @Override
-    InternalGeoGrid<InternalGeoHashGridBucket> create(
+    protected InternalGeoGrid<InternalGeoHashGridBucket> create(
         String name,
         int requiredSize,
         List<InternalGeoGridBucket> buckets,
@@ -50,12 +50,12 @@ public class InternalGeoHashGrid extends InternalGeoGrid<InternalGeoHashGridBuck
     }
 
     @Override
-    InternalGeoHashGridBucket createBucket(long hashAsLong, long docCount, InternalAggregations aggregations) {
+    protected InternalGeoHashGridBucket createBucket(long hashAsLong, long docCount, InternalAggregations aggregations) {
         return new InternalGeoHashGridBucket(hashAsLong, docCount, aggregations);
     }
 
     @Override
-    Reader<InternalGeoHashGridBucket> getBucketReader() {
+    protected Reader<InternalGeoHashGridBucket> getBucketReader() {
         return InternalGeoHashGridBucket::new;
     }
 

+ 3 - 3
server/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoTileGrid.java

@@ -40,7 +40,7 @@ public class InternalGeoTileGrid extends InternalGeoGrid<InternalGeoTileGridBuck
     }
 
     @Override
-    InternalGeoGrid<InternalGeoTileGridBucket> create(
+    protected InternalGeoGrid<InternalGeoTileGridBucket> create(
         String name,
         int requiredSize,
         List<InternalGeoGridBucket> buckets,
@@ -50,12 +50,12 @@ public class InternalGeoTileGrid extends InternalGeoGrid<InternalGeoTileGridBuck
     }
 
     @Override
-    InternalGeoTileGridBucket createBucket(long hashAsLong, long docCount, InternalAggregations aggregations) {
+    protected InternalGeoTileGridBucket createBucket(long hashAsLong, long docCount, InternalAggregations aggregations) {
         return new InternalGeoTileGridBucket(hashAsLong, docCount, aggregations);
     }
 
     @Override
-    Reader<InternalGeoTileGridBucket> getBucketReader() {
+    protected Reader<InternalGeoTileGridBucket> getBucketReader() {
         return InternalGeoTileGridBucket::new;
     }
 

+ 0 - 0
server/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorTestCase.java → test/framework/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorTestCase.java


+ 0 - 0
server/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridTestCase.java → test/framework/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridTestCase.java