Remove throws IOException from PipelineAggregationBuilder#create (#40222)

IOException are never thrown in any of the existing pipeline aggregation
builders. Removing the throws IOException from the create method allows
to remove it also from a couple of other methods which ends up simplifying
 AggregationPhase (one less catch).
This commit is contained in:
Luca Cavanna 2019-03-20 16:14:08 +01:00
parent 336c92e4d3
commit 48b0deef4f
22 changed files with 33 additions and 38 deletions

View File

@ -133,22 +133,18 @@ public class AggregationPhase implements SearchPhase {
}
}
context.queryResult().aggregations(new InternalAggregations(aggregations));
try {
List<PipelineAggregator> pipelineAggregators = context.aggregations().factories().createPipelineAggregators();
List<SiblingPipelineAggregator> siblingPipelineAggregators = new ArrayList<>(pipelineAggregators.size());
for (PipelineAggregator pipelineAggregator : pipelineAggregators) {
if (pipelineAggregator instanceof SiblingPipelineAggregator) {
siblingPipelineAggregators.add((SiblingPipelineAggregator) pipelineAggregator);
} else {
throw new AggregationExecutionException("Invalid pipeline aggregation named [" + pipelineAggregator.name()
+ "] of type [" + pipelineAggregator.getWriteableName() + "]. Only sibling pipeline aggregations are "
+ "allowed at the top level");
}
List<PipelineAggregator> pipelineAggregators = context.aggregations().factories().createPipelineAggregators();
List<SiblingPipelineAggregator> siblingPipelineAggregators = new ArrayList<>(pipelineAggregators.size());
for (PipelineAggregator pipelineAggregator : pipelineAggregators) {
if (pipelineAggregator instanceof SiblingPipelineAggregator) {
siblingPipelineAggregators.add((SiblingPipelineAggregator) pipelineAggregator);
} else {
throw new AggregationExecutionException("Invalid pipeline aggregation named [" + pipelineAggregator.name()
+ "] of type [" + pipelineAggregator.getWriteableName() + "]. Only sibling pipeline aggregations are "
+ "allowed at the top level");
}
context.queryResult().pipelineAggregators(siblingPipelineAggregators);
} catch (IOException e) {
throw new AggregationExecutionException("Failed to build top level pipeline aggregators", e);
}
context.queryResult().pipelineAggregators(siblingPipelineAggregators);
// disable aggregations so that they don't run on next pages in case of scrolling
context.aggregations(null);

View File

@ -175,7 +175,7 @@ public class AggregatorFactories {
this.pipelineAggregatorFactories = pipelineAggregators;
}
public List<PipelineAggregator> createPipelineAggregators() throws IOException {
public List<PipelineAggregator> createPipelineAggregators() {
List<PipelineAggregator> pipelineAggregators = new ArrayList<>(this.pipelineAggregatorFactories.size());
for (PipelineAggregationBuilder factory : this.pipelineAggregatorFactories) {
pipelineAggregators.add(factory.create());

View File

@ -24,7 +24,6 @@ import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
@ -76,7 +75,7 @@ public abstract class PipelineAggregationBuilder implements NamedWriteable, Base
*
* @return The created aggregator
*/
protected abstract PipelineAggregator create() throws IOException;
protected abstract PipelineAggregator create();
/** Associate metadata with this {@link PipelineAggregationBuilder}. */
@Override

View File

@ -89,7 +89,7 @@ public abstract class AbstractPipelineAggregationBuilder<PAB extends AbstractPip
doValidate(parent, factories, pipelineAggregatorFactories);
}
protected abstract PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException;
protected abstract PipelineAggregator createInternal(Map<String, Object> metaData);
/**
* Creates the pipeline aggregator
@ -97,7 +97,7 @@ public abstract class AbstractPipelineAggregationBuilder<PAB extends AbstractPip
* @return The created aggregator
*/
@Override
public final PipelineAggregator create() throws IOException {
public final PipelineAggregator create() {
PipelineAggregator aggregator = createInternal(this.metaData);
return aggregator;
}

View File

@ -46,7 +46,7 @@ public class AvgBucketPipelineAggregationBuilder extends BucketMetricsPipelineAg
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new AvgBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
}

View File

@ -104,7 +104,7 @@ public abstract class BucketMetricsPipelineAggregationBuilder<AF extends BucketM
}
@Override
protected abstract PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException;
protected abstract PipelineAggregator createInternal(Map<String, Object> metaData);
@Override
public void doValidate(AggregatorFactory<?> parent, Collection<AggregationBuilder> aggBuilders,

View File

@ -139,7 +139,7 @@ public class BucketScriptPipelineAggregationBuilder extends AbstractPipelineAggr
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new BucketScriptPipelineAggregator(name, bucketsPathsMap, script, formatter(), gapPolicy, metaData);
}

View File

@ -108,7 +108,7 @@ public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAg
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new BucketSelectorPipelineAggregator(name, bucketsPathsMap, script, gapPolicy, metaData);
}

View File

@ -139,7 +139,7 @@ public class BucketSortPipelineAggregationBuilder extends AbstractPipelineAggreg
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new BucketSortPipelineAggregator(name, sorts, from, size, gapPolicy, metaData);
}

View File

@ -88,7 +88,7 @@ public class CumulativeSumPipelineAggregationBuilder extends AbstractPipelineAgg
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new CumulativeSumPipelineAggregator(name, bucketsPaths, formatter(), metaData);
}

View File

@ -129,7 +129,7 @@ public class DerivativePipelineAggregationBuilder extends AbstractPipelineAggreg
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
DocValueFormat formatter;
if (format != null) {
formatter = new DocValueFormat.Decimal(format);

View File

@ -75,7 +75,7 @@ public class ExtendedStatsBucketPipelineAggregationBuilder
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new ExtendedStatsBucketPipelineAggregator(name, bucketsPaths, sigma, gapPolicy(), formatter(), metaData);
}

View File

@ -46,7 +46,7 @@ public class MaxBucketPipelineAggregationBuilder extends BucketMetricsPipelineAg
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new MaxBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
}

View File

@ -46,7 +46,7 @@ public class MinBucketPipelineAggregationBuilder extends BucketMetricsPipelineAg
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new MinBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
}

View File

@ -250,7 +250,7 @@ public class MovAvgPipelineAggregationBuilder extends AbstractPipelineAggregatio
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
// If the user doesn't set a preference for cost minimization, ask
// what the model prefers
boolean minimize = this.minimize == null ? model.minimizeByDefault() : this.minimize;

View File

@ -179,7 +179,7 @@ public class MovFnPipelineAggregationBuilder extends AbstractPipelineAggregation
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new MovFnPipelineAggregator(name, bucketsPathString, script, window, formatter(), gapPolicy, metaData);
}

View File

@ -112,7 +112,7 @@ public class PercentilesBucketPipelineAggregationBuilder
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new PercentilesBucketPipelineAggregator(name, percents, keyed, bucketsPaths, gapPolicy(), formatter(), metaData);
}

View File

@ -135,7 +135,7 @@ public class SerialDiffPipelineAggregationBuilder extends AbstractPipelineAggreg
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new SerialDiffPipelineAggregator(name, bucketsPaths, formatter(), gapPolicy, lag, metaData);
}

View File

@ -47,7 +47,7 @@ public class StatsBucketPipelineAggregationBuilder extends BucketMetricsPipeline
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new StatsBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
}

View File

@ -46,7 +46,7 @@ public class SumBucketPipelineAggregationBuilder extends BucketMetricsPipelineAg
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return new SumBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
}

View File

@ -442,7 +442,7 @@ public class SearchModuleTests extends ESTestCase {
}
@Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
protected PipelineAggregator createInternal(Map<String, Object> metaData) {
return null;
}

View File

@ -53,7 +53,7 @@ public class InternalAggregationsTests extends ESTestCase {
assertNull(InternalAggregations.reduce(aggs, Collections.emptyList(), reduceContext));
}
public void testNonFinalReduceTopLevelPipelineAggs() throws IOException {
public void testNonFinalReduceTopLevelPipelineAggs() {
InternalAggregation terms = new StringTerms("name", BucketOrder.key(true),
10, 1, Collections.emptyList(), Collections.emptyMap(), DocValueFormat.RAW, 25, false, 10, Collections.emptyList(), 0);
List<InternalAggregations> aggs = Collections.singletonList(new InternalAggregations(Collections.singletonList(terms)));
@ -66,7 +66,7 @@ public class InternalAggregationsTests extends ESTestCase {
assertEquals(1, reducedAggs.aggregations.size());
}
public void testFinalReduceTopLevelPipelineAggs() throws IOException {
public void testFinalReduceTopLevelPipelineAggs() {
InternalAggregation terms = new StringTerms("name", BucketOrder.key(true),
10, 1, Collections.emptyList(), Collections.emptyMap(), DocValueFormat.RAW, 25, false, 10, Collections.emptyList(), 0);