Skip to content

Commit

Permalink
Update access modifier to support extensibility
Browse files Browse the repository at this point in the history
Change access modifier from default to protected.
This will help to build new geo based aggregation
outside OpenSearch, by keeping GeoGrid Classes as base class.

Signed-off-by: Vijayan Balasubramanian <balasvij@amazon.com>
  • Loading branch information
VijayanB committed Oct 25, 2022
1 parent c3ae61c commit 8910f93
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Add support for GeoJson Point type in GeoPoint field ([#4597](https://github.com/opensearch-project/OpenSearch/pull/4597))
- Added missing no-jdk distributions ([#4722](https://github.com/opensearch-project/OpenSearch/pull/4722))
- Copy `build.sh` over from opensearch-build ([#4887](https://github.com/opensearch-project/OpenSearch/pull/4887))
- Update GeoGrid base class access modifier to support extensibility ([#4888](https://github.com/opensearch-project/OpenSearch/pull/4888))

### Dependencies
- Bumps `com.diffplug.spotless` from 6.9.1 to 6.10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import java.util.function.Function;

/**
* Base Aggregation Builder for geohash_grid and geotile_grid aggs
* Base Aggregation Builder for geogrid aggs
*
* @opensearch.internal
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public abstract class GeoGridAggregator<T extends InternalGeoGrid> extends Bucke
protected final ValuesSource.Numeric valuesSource;
protected final LongKeyedBucketOrds bucketOrds;

GeoGridAggregator(
protected GeoGridAggregator(
String name,
AggregatorFactories factories,
ValuesSource.Numeric valuesSource,
Expand Down Expand Up @@ -118,14 +118,14 @@ public void collect(int doc, long owningBucketOrd) throws IOException {
};
}

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ public GeoHashGridAggregator(
}

@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);
}

Expand All @@ -73,7 +78,8 @@ public InternalGeoHashGrid buildEmptyAggregation() {
return new InternalGeoHashGrid(name, requiredSize, Collections.emptyList(), metadata());
}

InternalGeoGridBucket newEmptyBucket() {
@Override
protected InternalGeoGridBucket newEmptyBucket() {
return new InternalGeoHashGridBucket(0, 0, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ public GeoTileGridAggregator(
}

@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);
}

Expand All @@ -74,7 +79,8 @@ public InternalGeoTileGrid buildEmptyAggregation() {
return new InternalGeoTileGrid(name, requiredSize, Collections.emptyList(), metadata());
}

InternalGeoGridBucket newEmptyBucket() {
@Override
protected InternalGeoGridBucket newEmptyBucket() {
return new InternalGeoTileGridBucket(0, 0, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,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.
Expand All @@ -86,7 +86,12 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeList(buckets);
}

abstract InternalGeoGrid create(String name, int requiredSize, List<InternalGeoGridBucket> buckets, Map<String, Object> metadata);
protected abstract InternalGeoGrid create(
String name,
int requiredSize,
List<InternalGeoGridBucket> buckets,
Map<String, Object> metadata
);

@Override
public List<InternalGeoGridBucket> getBuckets() {
Expand Down Expand Up @@ -140,7 +145,7 @@ protected InternalGeoGridBucket reduceBucket(List<InternalGeoGridBucket> buckets
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void writeTo(StreamOutput out) throws IOException {
aggregations.writeTo(out);
}

long hashAsLong() {
public long hashAsLong() {
return hashAsLong;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ public InternalGeoGridBucket createBucket(InternalAggregations aggregations, Int
}

@Override
InternalGeoGrid create(String name, int requiredSize, List buckets, Map metadata) {
protected InternalGeoGrid create(String name, int requiredSize, List buckets, Map metadata) {
return new InternalGeoHashGrid(name, requiredSize, buckets, metadata);
}

@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 getBucketReader() {
protected Reader getBucketReader() {
return InternalGeoHashGridBucket::new;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ public InternalGeoGridBucket createBucket(InternalAggregations aggregations, Int
}

@Override
InternalGeoGrid create(String name, int requiredSize, List buckets, Map metadata) {
protected InternalGeoGrid create(String name, int requiredSize, List buckets, Map metadata) {
return new InternalGeoTileGrid(name, requiredSize, buckets, metadata);
}

@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 getBucketReader() {
protected Reader getBucketReader() {
return InternalGeoTileGridBucket::new;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static ObjectParser<ParsedGeoGrid, Void> createParser(
return parser;
}

protected void setName(String name) {
public void setName(String name) {
super.setName(name);
}
}

0 comments on commit 8910f93

Please sign in to comment.