Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed ValuesSourceRegistry.registerAny() #55747

Merged
merged 6 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ public class MissingAggregator extends BucketsAggregator implements SingleBucket

private final ValuesSource valuesSource;

public MissingAggregator(String name, AggregatorFactories factories, ValuesSource valuesSource,
SearchContext aggregationContext, Aggregator parent, Map<String, Object> metadata) throws IOException {
public MissingAggregator(
String name,
AggregatorFactories factories,
ValuesSource valuesSource,
SearchContext aggregationContext,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
super(name, factories, aggregationContext, parent, metadata);
this.valuesSource = valuesSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,14 @@
import org.elasticsearch.search.internal.SearchContext;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class MissingAggregatorFactory extends ValuesSourceAggregatorFactory {

public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(
MissingAggregationBuilder.NAME,
List.of(
CoreValuesSourceType.NUMERIC,
CoreValuesSourceType.BYTES,
CoreValuesSourceType.GEOPOINT,
CoreValuesSourceType.RANGE,
CoreValuesSourceType.IP,
CoreValuesSourceType.BOOLEAN,
CoreValuesSourceType.DATE
),
(MissingAggregatorSupplier) MissingAggregator::new
);
MissingAggregationBuilder.NAME, CoreValuesSourceType.ALL,
(MissingAggregatorSupplier) MissingAggregator::new);
}

public MissingAggregatorFactory(String name, ValuesSourceConfig config, QueryShardContext queryShardContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
/**
* An aggregator that computes approximate counts of unique values.
*/
class CardinalityAggregator extends NumericMetricsAggregator.SingleValue {
public class CardinalityAggregator extends NumericMetricsAggregator.SingleValue {

private final int precision;
private final ValuesSource valuesSource;
Expand All @@ -60,12 +60,13 @@ class CardinalityAggregator extends NumericMetricsAggregator.SingleValue {

private Collector collector;

CardinalityAggregator(String name,
ValuesSource valuesSource,
int precision,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
public CardinalityAggregator(
String name,
ValuesSource valuesSource,
int precision,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
super(name, context, parent, metadata);
this.valuesSource = valuesSource;
this.precision = precision;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
Expand All @@ -48,22 +49,9 @@ class CardinalityAggregatorFactory extends ValuesSourceAggregatorFactory {
this.precisionThreshold = precisionThreshold;
}

static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.registerAny(CardinalityAggregationBuilder.NAME, cardinalityAggregatorSupplier());
}

private static CardinalityAggregatorSupplier cardinalityAggregatorSupplier(){
return new CardinalityAggregatorSupplier() {
@Override
public Aggregator build(String name,
ValuesSource valuesSource,
int precision,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new CardinalityAggregator(name, valuesSource, precision, context, parent, metadata);
}
};
public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(CardinalityAggregationBuilder.NAME, CoreValuesSourceType.ALL,
(CardinalityAggregatorSupplier) CardinalityAggregator::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@
* This aggregator works in a multi-bucket mode, that is, when serves as a sub-aggregator, a single aggregator instance aggregates the
* counts for all buckets owned by the parent aggregator)
*/
class ValueCountAggregator extends NumericMetricsAggregator.SingleValue {
public class ValueCountAggregator extends NumericMetricsAggregator.SingleValue {

final ValuesSource valuesSource;

// a count per bucket
LongArray counts;

ValueCountAggregator(String name, ValuesSource valuesSource,
SearchContext aggregationContext, Aggregator parent, Map<String, Object> metadata) throws IOException {
public ValueCountAggregator(
String name,
ValuesSource valuesSource,
SearchContext aggregationContext,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
super(name, aggregationContext, parent, metadata);
this.valuesSource = valuesSource;
if (valuesSource != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
Expand All @@ -37,17 +38,8 @@
class ValueCountAggregatorFactory extends ValuesSourceAggregatorFactory {

public static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.registerAny(ValueCountAggregationBuilder.NAME,
new ValueCountAggregatorSupplier() {
@Override
public Aggregator build(String name,
ValuesSource valuesSource,
SearchContext aggregationContext,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new ValueCountAggregator(name, valuesSource, aggregationContext, parent, metadata);
}
});
builder.register(ValueCountAggregationBuilder.NAME, CoreValuesSourceType.ALL,
(ValueCountAggregatorSupplier) ValueCountAggregator::new);
}

ValueCountAggregatorFactory(String name, ValuesSourceConfig config, QueryShardContext queryShardContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@

import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.function.LongSupplier;

/**
* {@link CoreValuesSourceType} holds the {@link ValuesSourceType} implementations for the core aggregations package.
*/
public enum CoreValuesSourceType implements ValuesSourceType {

NUMERIC() {
@Override
public ValuesSource getEmpty() {
Expand Down Expand Up @@ -288,4 +291,6 @@ public String value() {
return name().toLowerCase(Locale.ROOT);
}

/** List containing all members of the enumeration. */
public static List<ValuesSourceType> ALL = Arrays.asList(CoreValuesSourceType.values());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ALL might be a bit confusing here. I wonder if renaming it into ALL_CORE or using Arrays.asList(CoreValuesSourceType.values()) instead of the constant will better demonstrate the actual scope here for future readers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it seemed clear that CoreValuesSourceType.ALL is about all core VST. I renamed it to CoreValuesSourceType.ALL_CORE hoping that this can't be misunderstood.

}
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,6 @@ public void register(String aggregationName, List<ValuesSourceType> valuesSource
}, aggregatorSupplier);
}

/**
* Register an aggregator that applies to any values source type. This is a convenience method for aggregations that do not care at
* all about the types of their inputs. Aggregations using this version of registration should not make any other registrations, as
* the aggregator registered using this function will be applied in all cases.
*
* @param aggregationName The name of the family of aggregations, typically found via
* {@link ValuesSourceAggregationBuilder#getType()}
* @param aggregatorSupplier An Aggregation-specific specialization of AggregatorSupplier which will construct the mapped aggregator
* from the aggregation standard set of parameters.
*/
public void registerAny(String aggregationName, AggregatorSupplier aggregatorSupplier) {
register(aggregationName, (ignored) -> true, aggregatorSupplier);
}


public ValuesSourceRegistry build() {
return new ValuesSourceRegistry(aggregatorRegistry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@
import org.elasticsearch.plugins.IngestPlugin;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.search.aggregations.metrics.CardinalityAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.CardinalityAggregator;
import org.elasticsearch.search.aggregations.metrics.CardinalityAggregatorSupplier;
import org.elasticsearch.search.aggregations.metrics.GeoBoundsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.GeoBoundsAggregatorSupplier;
import org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.ValueCountAggregator;
import org.elasticsearch.search.aggregations.metrics.ValueCountAggregatorSupplier;
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;
import org.elasticsearch.xpack.spatial.search.aggregations.metrics.GeoShapeBoundsAggregator;
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;

Expand Down Expand Up @@ -62,7 +68,11 @@ public List<QuerySpec<?>> getQueries() {

@Override
public List<Consumer<ValuesSourceRegistry.Builder>> getAggregationExtentions() {
return List.of(SpatialPlugin::registerGeoShapeBoundsAggregator);
return List.of(
SpatialPlugin::registerGeoShapeBoundsAggregator,
SpatialPlugin::registerValueCountAggregator,
SpatialPlugin::registerCardinalityAggregator
);
}

@Override
Expand All @@ -76,4 +86,15 @@ public static void registerGeoShapeBoundsAggregator(ValuesSourceRegistry.Builder
-> new GeoShapeBoundsAggregator(name, aggregationContext, parent, (GeoShapeValuesSource) valuesSource,
wrapLongitude, metadata));
}

public static void registerValueCountAggregator(ValuesSourceRegistry.Builder builder) {
builder.register(ValueCountAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(),
(ValueCountAggregatorSupplier) ValueCountAggregator::new
);
}

public static void registerCardinalityAggregator(ValuesSourceRegistry.Builder builder) {
builder.register(CardinalityAggregationBuilder.NAME, GeoShapeValuesSourceType.instance(),
(CardinalityAggregatorSupplier) CardinalityAggregator::new);
}
}