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)); context.queryResult().aggregations(new InternalAggregations(aggregations));
try { List<PipelineAggregator> pipelineAggregators = context.aggregations().factories().createPipelineAggregators();
List<PipelineAggregator> pipelineAggregators = context.aggregations().factories().createPipelineAggregators(); List<SiblingPipelineAggregator> siblingPipelineAggregators = new ArrayList<>(pipelineAggregators.size());
List<SiblingPipelineAggregator> siblingPipelineAggregators = new ArrayList<>(pipelineAggregators.size()); for (PipelineAggregator pipelineAggregator : pipelineAggregators) {
for (PipelineAggregator pipelineAggregator : pipelineAggregators) { if (pipelineAggregator instanceof SiblingPipelineAggregator) {
if (pipelineAggregator instanceof SiblingPipelineAggregator) { siblingPipelineAggregators.add((SiblingPipelineAggregator) pipelineAggregator);
siblingPipelineAggregators.add((SiblingPipelineAggregator) pipelineAggregator); } else {
} else { throw new AggregationExecutionException("Invalid pipeline aggregation named [" + pipelineAggregator.name()
throw new AggregationExecutionException("Invalid pipeline aggregation named [" + pipelineAggregator.name() + "] of type [" + pipelineAggregator.getWriteableName() + "]. Only sibling pipeline aggregations are "
+ "] of type [" + pipelineAggregator.getWriteableName() + "]. Only sibling pipeline aggregations are " + "allowed at the top level");
+ "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 // disable aggregations so that they don't run on next pages in case of scrolling
context.aggregations(null); context.aggregations(null);

View File

@ -175,7 +175,7 @@ public class AggregatorFactories {
this.pipelineAggregatorFactories = pipelineAggregators; this.pipelineAggregatorFactories = pipelineAggregators;
} }
public List<PipelineAggregator> createPipelineAggregators() throws IOException { public List<PipelineAggregator> createPipelineAggregators() {
List<PipelineAggregator> pipelineAggregators = new ArrayList<>(this.pipelineAggregatorFactories.size()); List<PipelineAggregator> pipelineAggregators = new ArrayList<>(this.pipelineAggregatorFactories.size());
for (PipelineAggregationBuilder factory : this.pipelineAggregatorFactories) { for (PipelineAggregationBuilder factory : this.pipelineAggregatorFactories) {
pipelineAggregators.add(factory.create()); 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.AggregatorFactories.Builder;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
@ -76,7 +75,7 @@ public abstract class PipelineAggregationBuilder implements NamedWriteable, Base
* *
* @return The created aggregator * @return The created aggregator
*/ */
protected abstract PipelineAggregator create() throws IOException; protected abstract PipelineAggregator create();
/** Associate metadata with this {@link PipelineAggregationBuilder}. */ /** Associate metadata with this {@link PipelineAggregationBuilder}. */
@Override @Override

View File

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

View File

@ -46,7 +46,7 @@ public class AvgBucketPipelineAggregationBuilder extends BucketMetricsPipelineAg
} }
@Override @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); return new AvgBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
} }

View File

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

View File

@ -139,7 +139,7 @@ public class BucketScriptPipelineAggregationBuilder extends AbstractPipelineAggr
} }
@Override @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); return new BucketScriptPipelineAggregator(name, bucketsPathsMap, script, formatter(), gapPolicy, metaData);
} }

View File

@ -108,7 +108,7 @@ public class BucketSelectorPipelineAggregationBuilder extends AbstractPipelineAg
} }
@Override @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); return new BucketSelectorPipelineAggregator(name, bucketsPathsMap, script, gapPolicy, metaData);
} }

View File

@ -139,7 +139,7 @@ public class BucketSortPipelineAggregationBuilder extends AbstractPipelineAggreg
} }
@Override @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); return new BucketSortPipelineAggregator(name, sorts, from, size, gapPolicy, metaData);
} }

View File

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

View File

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

View File

@ -75,7 +75,7 @@ public class ExtendedStatsBucketPipelineAggregationBuilder
} }
@Override @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); return new ExtendedStatsBucketPipelineAggregator(name, bucketsPaths, sigma, gapPolicy(), formatter(), metaData);
} }

View File

@ -46,7 +46,7 @@ public class MaxBucketPipelineAggregationBuilder extends BucketMetricsPipelineAg
} }
@Override @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); return new MaxBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
} }

View File

@ -46,7 +46,7 @@ public class MinBucketPipelineAggregationBuilder extends BucketMetricsPipelineAg
} }
@Override @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); return new MinBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
} }

View File

@ -250,7 +250,7 @@ public class MovAvgPipelineAggregationBuilder extends AbstractPipelineAggregatio
} }
@Override @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 // If the user doesn't set a preference for cost minimization, ask
// what the model prefers // what the model prefers
boolean minimize = this.minimize == null ? model.minimizeByDefault() : this.minimize; boolean minimize = this.minimize == null ? model.minimizeByDefault() : this.minimize;

View File

@ -179,7 +179,7 @@ public class MovFnPipelineAggregationBuilder extends AbstractPipelineAggregation
} }
@Override @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); return new MovFnPipelineAggregator(name, bucketsPathString, script, window, formatter(), gapPolicy, metaData);
} }

View File

@ -112,7 +112,7 @@ public class PercentilesBucketPipelineAggregationBuilder
} }
@Override @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); return new PercentilesBucketPipelineAggregator(name, percents, keyed, bucketsPaths, gapPolicy(), formatter(), metaData);
} }

View File

@ -135,7 +135,7 @@ public class SerialDiffPipelineAggregationBuilder extends AbstractPipelineAggreg
} }
@Override @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); return new SerialDiffPipelineAggregator(name, bucketsPaths, formatter(), gapPolicy, lag, metaData);
} }

View File

@ -47,7 +47,7 @@ public class StatsBucketPipelineAggregationBuilder extends BucketMetricsPipeline
} }
@Override @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); return new StatsBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
} }

View File

@ -46,7 +46,7 @@ public class SumBucketPipelineAggregationBuilder extends BucketMetricsPipelineAg
} }
@Override @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); return new SumBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
} }

View File

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

View File

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