Clean up Aggregator Supplier Boiler Plate (#57442) (#57452)

This commit is contained in:
Mark Tozzi 2020-06-01 14:21:07 -04:00 committed by GitHub
parent 12813d5918
commit 1f500583b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 80 additions and 218 deletions

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.bucket.range;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactories;
@ -37,7 +36,6 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
public class AbstractRangeAggregatorFactory<R extends Range> extends ValuesSourceAggregatorFactory {
@ -50,24 +48,10 @@ public class AbstractRangeAggregatorFactory<R extends Range> extends ValuesSourc
public static void registerAggregators(ValuesSourceRegistry.Builder builder,
String aggregationName) {
builder.register(aggregationName,
Arrays.asList(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
new RangeAggregatorSupplier() {
@Override
public Aggregator build(String name,
AggregatorFactories factories,
Numeric valuesSource,
DocValueFormat format,
InternalRange.Factory rangeFactory,
Range[] ranges,
boolean keyed,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new RangeAggregator(name, factories, valuesSource, format, rangeFactory, ranges, keyed, context, parent,
metadata);
}
});
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
(RangeAggregatorSupplier) RangeAggregator::new);
}
public AbstractRangeAggregatorFactory(String name,
String aggregationTypeName,
ValuesSourceConfig config,

View File

@ -31,6 +31,7 @@ import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.LeafBucketCollector;
import org.elasticsearch.search.aggregations.LeafBucketCollectorBase;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
@ -45,11 +46,11 @@ class AvgAggregator extends NumericMetricsAggregator.SingleValue {
DoubleArray compensations;
DocValueFormat format;
AvgAggregator(String name, ValuesSource.Numeric valuesSource, DocValueFormat formatter, SearchContext context,
Aggregator parent, Map<String, Object> metadata) throws IOException {
AvgAggregator(String name, ValuesSourceConfig valuesSourceConfig, ValuesSource valuesSource, SearchContext context,
Aggregator parent, Map<String, Object> metadata) throws IOException {
super(name, context, parent, metadata);
this.valuesSource = valuesSource;
this.format = formatter;
this.valuesSource = (ValuesSource.Numeric) valuesSource;
this.format = valuesSourceConfig.format();
if (valuesSource != null) {
final BigArrays bigArrays = context.bigArrays();
counts = bigArrays.newLongArray(1, true);

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactories;
@ -28,14 +27,12 @@ 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.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
class AvgAggregatorFactory extends ValuesSourceAggregatorFactory {
@ -48,25 +45,16 @@ class AvgAggregatorFactory extends ValuesSourceAggregatorFactory {
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(AvgAggregationBuilder.NAME,
Arrays.asList(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
new MetricAggregatorSupplier() {
@Override
public Aggregator build(String name,
ValuesSource valuesSource,
DocValueFormat formatter,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new AvgAggregator(name, (Numeric) valuesSource, formatter, context, parent, metadata);
}
});
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
(MetricAggregatorSupplier) AvgAggregator::new
);
}
@Override
protected Aggregator createUnmapped(SearchContext searchContext,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new AvgAggregator(name, null, config.format(), searchContext, parent, metadata);
return new AvgAggregator(name, config, null, searchContext, parent, metadata);
}
@Override
@ -82,6 +70,6 @@ class AvgAggregatorFactory extends ValuesSourceAggregatorFactory {
throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" +
aggregatorSupplier.getClass().toString() + "]");
}
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, valuesSource, config.format(), searchContext, parent, metadata);
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, metadata);
}
}

View File

@ -50,9 +50,9 @@ final class GeoBoundsAggregator extends MetricsAggregator {
DoubleArray negRights;
GeoBoundsAggregator(String name, SearchContext aggregationContext, Aggregator parent,
ValuesSource.GeoPoint valuesSource, boolean wrapLongitude, Map<String, Object> metadata) throws IOException {
ValuesSource valuesSource, boolean wrapLongitude, Map<String, Object> metadata) throws IOException {
super(name, aggregationContext, parent, metadata);
this.valuesSource = valuesSource;
this.valuesSource = (ValuesSource.GeoPoint) valuesSource;
this.wrapLongitude = wrapLongitude;
if (valuesSource != null) {
final BigArrays bigArrays = context.bigArrays();

View File

@ -76,8 +76,6 @@ class GeoBoundsAggregatorFactory extends ValuesSourceAggregatorFactory {
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(GeoBoundsAggregationBuilder.NAME, CoreValuesSourceType.GEOPOINT,
(GeoBoundsAggregatorSupplier) (name, aggregationContext, parent, valuesSource, wrapLongitude, metadata)
-> new GeoBoundsAggregator(name, aggregationContext, parent, (ValuesSource.GeoPoint) valuesSource,
wrapLongitude, metadata));
(GeoBoundsAggregatorSupplier) GeoBoundsAggregator::new);
}
}

View File

@ -45,9 +45,9 @@ final class GeoCentroidAggregator extends MetricsAggregator {
private LongArray counts;
GeoCentroidAggregator(String name, SearchContext context, Aggregator parent,
ValuesSource.GeoPoint valuesSource, Map<String, Object> metadata) throws IOException {
ValuesSource valuesSource, Map<String, Object> metadata) throws IOException {
super(name, context, parent, metadata);
this.valuesSource = valuesSource;
this.valuesSource = (ValuesSource.GeoPoint) valuesSource;
if (valuesSource != null) {
final BigArrays bigArrays = context.bigArrays();
lonSum = bigArrays.newDoubleArray(1, true);

View File

@ -71,7 +71,6 @@ class GeoCentroidAggregatorFactory extends ValuesSourceAggregatorFactory {
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(GeoCentroidAggregationBuilder.NAME, CoreValuesSourceType.GEOPOINT,
(GeoCentroidAggregatorSupplier) (name, context, parent, valuesSource, metadata) ->
new GeoCentroidAggregator(name, context, parent, (ValuesSource.GeoPoint) valuesSource, metadata));
(GeoCentroidAggregatorSupplier) GeoCentroidAggregator::new);
}
}

View File

@ -58,11 +58,11 @@ class MaxAggregator extends NumericMetricsAggregator.SingleValue {
MaxAggregator(String name,
ValuesSourceConfig config,
ValuesSource.Numeric valuesSource,
ValuesSource valuesSource,
SearchContext context,
Aggregator parent, Map<String, Object> metadata) throws IOException {
super(name, context, parent, metadata);
this.valuesSource = valuesSource;
this.valuesSource = (ValuesSource.Numeric) valuesSource;
if (valuesSource != null) {
maxes = context.bigArrays().newDoubleArray(1, false);
maxes.fill(0, maxes.size(), Double.NEGATIVE_INFINITY);

View File

@ -27,32 +27,20 @@ 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.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
class MaxAggregatorFactory extends ValuesSourceAggregatorFactory {
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(MaxAggregationBuilder.NAME,
Arrays.asList(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
new MinMaxAggregatorSupplier() {
@Override
public Aggregator build(String name,
ValuesSourceConfig config,
ValuesSource valuesSource,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new MaxAggregator(name, config, (Numeric) valuesSource, context, parent, metadata);
}
});
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
(MetricAggregatorSupplier) MaxAggregator::new);
}
MaxAggregatorFactory(String name, ValuesSourceConfig config, QueryShardContext queryShardContext,
@ -77,11 +65,10 @@ class MaxAggregatorFactory extends ValuesSourceAggregatorFactory {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
MaxAggregationBuilder.NAME);
if (aggregatorSupplier instanceof MinMaxAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected MinMaxAggregatorSupplier, found [" +
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" +
aggregatorSupplier.getClass().toString() + "]");
}
return ((MinMaxAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent,
metadata);
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, metadata);
}
}

View File

@ -50,16 +50,16 @@ public class MedianAbsoluteDeviationAggregator extends NumericMetricsAggregator.
private ObjectArray<TDigestState> valueSketches;
MedianAbsoluteDeviationAggregator(String name,
SearchContext context,
@Nullable ValuesSource valuesSource,
DocValueFormat format,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata,
@Nullable ValuesSource.Numeric valuesSource,
DocValueFormat format,
double compression) throws IOException {
super(name, context, parent, metadata);
this.valuesSource = valuesSource;
this.valuesSource = (ValuesSource.Numeric) valuesSource;
this.format = Objects.requireNonNull(format);
this.compression = compression;
this.valueSketches = context.bigArrays().newObjectArray(1);

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactories;
@ -54,27 +53,7 @@ public class MedianAbsoluteDeviationAggregatorFactory extends ValuesSourceAggreg
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(MedianAbsoluteDeviationAggregationBuilder.NAME,
CoreValuesSourceType.NUMERIC,
new MedianAbsoluteDeviationAggregatorSupplier() {
@Override
public Aggregator build(String name,
ValuesSource valuesSource,
DocValueFormat format,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata,
double compression) throws IOException {
return new MedianAbsoluteDeviationAggregator(
name,
context,
parent,
metadata,
(ValuesSource.Numeric) valuesSource,
format,
compression
);
}
});
CoreValuesSourceType.NUMERIC, (MedianAbsoluteDeviationAggregatorSupplier) MedianAbsoluteDeviationAggregator::new);
}
@Override
@ -84,11 +63,11 @@ public class MedianAbsoluteDeviationAggregatorFactory extends ValuesSourceAggreg
return new MedianAbsoluteDeviationAggregator(
name,
null,
config.format(),
searchContext,
parent,
metadata,
null,
config.format(),
compression
);
}

View File

@ -18,10 +18,10 @@
*/
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
@ -29,8 +29,8 @@ import java.util.Map;
public interface MetricAggregatorSupplier extends AggregatorSupplier {
Aggregator build(String name,
ValuesSourceConfig valuesSourceConfig,
ValuesSource valuesSource,
DocValueFormat format,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException;

View File

@ -61,12 +61,12 @@ class MinAggregator extends NumericMetricsAggregator.SingleValue {
MinAggregator(String name,
ValuesSourceConfig config,
ValuesSource.Numeric valuesSource,
ValuesSource valuesSource,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
super(name, context, parent, metadata);
this.valuesSource = valuesSource;
this.valuesSource = (ValuesSource.Numeric) valuesSource;
if (valuesSource != null) {
mins = context.bigArrays().newDoubleArray(1, false);
mins.fill(0, mins.size(), Double.POSITIVE_INFINITY);

View File

@ -27,32 +27,20 @@ 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.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
class MinAggregatorFactory extends ValuesSourceAggregatorFactory {
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(MinAggregationBuilder.NAME,
Arrays.asList(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
new MinMaxAggregatorSupplier() {
@Override
public Aggregator build(String name,
ValuesSourceConfig config,
ValuesSource valuesSource,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new MinAggregator(name, config, (Numeric) valuesSource, context, parent, metadata);
}
});
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
(MetricAggregatorSupplier) MinAggregator::new);
}
MinAggregatorFactory(String name, ValuesSourceConfig config, QueryShardContext queryShardContext,
@ -77,10 +65,10 @@ class MinAggregatorFactory extends ValuesSourceAggregatorFactory {
AggregatorSupplier aggregatorSupplier = queryShardContext.getValuesSourceRegistry().getAggregator(config.valueSourceType(),
MinAggregationBuilder.NAME);
if (aggregatorSupplier instanceof MinMaxAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected MinMaxAggregatorSupplier, found [" +
if (aggregatorSupplier instanceof MetricAggregatorSupplier == false) {
throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" +
aggregatorSupplier.getClass().toString() + "]");
}
return ((MinMaxAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, metadata);
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, metadata);
}
}

View File

@ -1,37 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.support.AggregatorSupplier;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
import java.util.Map;
public interface MinMaxAggregatorSupplier extends AggregatorSupplier {
Aggregator build(String name,
ValuesSourceConfig config,
ValuesSource valuesSource,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException;
}

View File

@ -31,6 +31,7 @@ import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.LeafBucketCollector;
import org.elasticsearch.search.aggregations.LeafBucketCollectorBase;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
@ -47,10 +48,10 @@ class StatsAggregator extends NumericMetricsAggregator.MultiValue {
DoubleArray mins;
DoubleArray maxes;
StatsAggregator(String name, ValuesSource.Numeric valuesSource, DocValueFormat format,
SearchContext context, Aggregator parent, Map<String, Object> metadata) throws IOException {
StatsAggregator(String name, ValuesSourceConfig valuesSourceConfig, ValuesSource valuesSource,
SearchContext context, Aggregator parent, Map<String, Object> metadata) throws IOException {
super(name, context, parent, metadata);
this.valuesSource = valuesSource;
this.valuesSource = (ValuesSource.Numeric) valuesSource;
if (valuesSource != null) {
final BigArrays bigArrays = context.bigArrays();
counts = bigArrays.newLongArray(1, true);
@ -61,7 +62,7 @@ class StatsAggregator extends NumericMetricsAggregator.MultiValue {
maxes = bigArrays.newDoubleArray(1, false);
maxes.fill(0, maxes.size(), Double.NEGATIVE_INFINITY);
}
this.format = format;
this.format = valuesSourceConfig.format();
}
@Override

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactories;
@ -28,14 +27,12 @@ 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.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
class StatsAggregatorFactory extends ValuesSourceAggregatorFactory {
@ -51,25 +48,15 @@ class StatsAggregatorFactory extends ValuesSourceAggregatorFactory {
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(StatsAggregationBuilder.NAME,
Arrays.asList(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
new MetricAggregatorSupplier() {
@Override
public Aggregator build(String name,
ValuesSource valuesSource,
DocValueFormat formatter,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new StatsAggregator(name, (Numeric) valuesSource, formatter, context, parent, metadata);
}
});
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
(MetricAggregatorSupplier) StatsAggregator::new);
}
@Override
protected Aggregator createUnmapped(SearchContext searchContext,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new StatsAggregator(name, null, config.format(), searchContext, parent, metadata);
return new StatsAggregator(name, config, null, searchContext, parent, metadata);
}
@Override
@ -85,6 +72,6 @@ class StatsAggregatorFactory extends ValuesSourceAggregatorFactory {
throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" +
aggregatorSupplier.getClass().toString() + "]");
}
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, valuesSource, config.format(), searchContext, parent, metadata);
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, metadata);
}
}

View File

@ -30,6 +30,7 @@ import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.LeafBucketCollector;
import org.elasticsearch.search.aggregations.LeafBucketCollectorBase;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
@ -43,11 +44,11 @@ public class SumAggregator extends NumericMetricsAggregator.SingleValue {
private DoubleArray sums;
private DoubleArray compensations;
SumAggregator(String name, ValuesSource.Numeric valuesSource, DocValueFormat formatter, SearchContext context,
Aggregator parent, Map<String, Object> metadata) throws IOException {
SumAggregator(String name, ValuesSourceConfig valuesSourceConfig, ValuesSource valuesSource, SearchContext context,
Aggregator parent, Map<String, Object> metadata) throws IOException {
super(name, context, parent, metadata);
this.valuesSource = valuesSource;
this.format = formatter;
this.valuesSource = (ValuesSource.Numeric) valuesSource;
this.format = valuesSourceConfig.format();
if (valuesSource != null) {
sums = context.bigArrays().newDoubleArray(1, true);
compensations = context.bigArrays().newDoubleArray(1, true);

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactories;
@ -28,14 +27,12 @@ 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.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceRegistry;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
class SumAggregatorFactory extends ValuesSourceAggregatorFactory {
@ -51,18 +48,8 @@ class SumAggregatorFactory extends ValuesSourceAggregatorFactory {
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(SumAggregationBuilder.NAME,
Arrays.asList(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
new MetricAggregatorSupplier() {
@Override
public Aggregator build(String name,
ValuesSource valuesSource,
DocValueFormat formatter,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new SumAggregator(name, (Numeric) valuesSource, formatter, context, parent, metadata);
}
});
org.elasticsearch.common.collect.List.of(CoreValuesSourceType.NUMERIC, CoreValuesSourceType.DATE, CoreValuesSourceType.BOOLEAN),
(MetricAggregatorSupplier) SumAggregator::new);
}
@Override
@ -70,7 +57,7 @@ class SumAggregatorFactory extends ValuesSourceAggregatorFactory {
Aggregator parent,
Map<String, Object> metadata)
throws IOException {
return new SumAggregator(name, null, config.format(), searchContext, parent, metadata);
return new SumAggregator(name, config, null, searchContext, parent, metadata);
}
@Override
@ -86,6 +73,6 @@ class SumAggregatorFactory extends ValuesSourceAggregatorFactory {
throw new AggregationExecutionException("Registry miss-match - expected MetricAggregatorSupplier, found [" +
aggregatorSupplier.getClass().toString() + "]");
}
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, valuesSource, config.format(), searchContext, parent, metadata);
return ((MetricAggregatorSupplier) aggregatorSupplier).build(name, config, valuesSource, searchContext, parent, metadata);
}
}

View File

@ -68,8 +68,14 @@ public class AnalyticsAggregatorFactory {
public static void registerHistoBackedSumAggregator(ValuesSourceRegistry.Builder builder) {
builder.register(SumAggregationBuilder.NAME,
AnalyticsValuesSourceType.HISTOGRAM,
(MetricAggregatorSupplier) (name, valuesSource, format, context, parent, metadata) ->
new HistoBackedSumAggregator(name, (HistogramValuesSource.Histogram) valuesSource, format, context, parent, metadata)
(MetricAggregatorSupplier) (name, valuesSourceConfig, valuesSource, context, parent, metadata) -> new HistoBackedSumAggregator(
name,
(HistogramValuesSource.Histogram) valuesSource,
valuesSourceConfig.format(),
context,
parent,
metadata
)
);
}
@ -84,8 +90,14 @@ public class AnalyticsAggregatorFactory {
public static void registerHistoBackedAverageAggregator(ValuesSourceRegistry.Builder builder) {
builder.register(AvgAggregationBuilder.NAME,
AnalyticsValuesSourceType.HISTOGRAM,
(MetricAggregatorSupplier) (name, valuesSource, format, context, parent, metadata) ->
new HistoBackedAvgAggregator(name, (HistogramValuesSource.Histogram) valuesSource, format, context, parent, metadata)
(MetricAggregatorSupplier) (name, valuesSourceConfig, valuesSource, context, parent, metadata) -> new HistoBackedAvgAggregator(
name,
(HistogramValuesSource.Histogram) valuesSource,
valuesSourceConfig.format(),
context,
parent,
metadata
)
);
}
}

View File

@ -48,11 +48,11 @@ public class StringStatsAggregator extends MetricsAggregator {
/** Map that stores the number of occurrences for each character. */
Map<Character, LongArray> charOccurrences;
StringStatsAggregator(String name, boolean showDistribution, ValuesSource.Bytes valuesSource, DocValueFormat format,
StringStatsAggregator(String name, ValuesSource valuesSource, boolean showDistribution, DocValueFormat format,
SearchContext context, Aggregator parent, Map<String, Object> metadata) throws IOException {
super(name, context, parent, metadata);
this.showDistribution = showDistribution;
this.valuesSource = valuesSource;
this.valuesSource = (ValuesSource.Bytes) valuesSource;
if (valuesSource != null) {
final BigArrays bigArrays = context.bigArrays();
count = bigArrays.newLongArray(1, true);

View File

@ -7,7 +7,6 @@
package org.elasticsearch.xpack.analytics.stringstats;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactories;
@ -38,26 +37,14 @@ class StringStatsAggregatorFactory extends ValuesSourceAggregatorFactory {
static void registerAggregators(ValuesSourceRegistry.Builder builder) {
builder.register(StringStatsAggregationBuilder.NAME,
CoreValuesSourceType.BYTES, new StringStatsAggregatorSupplier() {
@Override
public Aggregator build(String name,
ValuesSource valuesSource,
boolean showDistribution,
DocValueFormat format,
SearchContext context,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new StringStatsAggregator(name, showDistribution, (ValuesSource.Bytes) valuesSource,
format, context, parent, metadata);
}
});
CoreValuesSourceType.BYTES, (StringStatsAggregatorSupplier) StringStatsAggregator::new);
}
@Override
protected Aggregator createUnmapped(SearchContext searchContext,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new StringStatsAggregator(name, showDistribution,null, config.format(), searchContext, parent, metadata);
return new StringStatsAggregator(name, null, showDistribution, config.format(), searchContext, parent, metadata);
}
@Override