Skip to content

Commit

Permalink
Move bucket_selector agg to the agg module (#91355)
Browse files Browse the repository at this point in the history
This moves the bucket selector aggregation to the aggregations module
and ports all of it's ESIntegTestCase tests to REST tests which gets us
mixed cluster testing.

Relates to #26220 Relates to #90283
  • Loading branch information
nik9000 authored Nov 10, 2022
1 parent 3ece828 commit 76bd44f
Show file tree
Hide file tree
Showing 14 changed files with 383 additions and 678 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.elasticsearch.aggregations.bucket.histogram.InternalAutoDateHistogram;
import org.elasticsearch.aggregations.bucket.timeseries.InternalTimeSeries;
import org.elasticsearch.aggregations.bucket.timeseries.TimeSeriesAggregationBuilder;
import org.elasticsearch.aggregations.pipeline.BucketSelectorPipelineAggregationBuilder;
import org.elasticsearch.aggregations.pipeline.BucketSortPipelineAggregationBuilder;
import org.elasticsearch.aggregations.pipeline.Derivative;
import org.elasticsearch.aggregations.pipeline.DerivativePipelineAggregationBuilder;
Expand Down Expand Up @@ -62,6 +63,11 @@ public List<AggregationSpec> getAggregations() {
@Override
public List<PipelineAggregationSpec> getPipelineAggregations() {
return List.of(
new PipelineAggregationSpec(
BucketSelectorPipelineAggregationBuilder.NAME,
BucketSelectorPipelineAggregationBuilder::new,
BucketSelectorPipelineAggregationBuilder::parse
),
new PipelineAggregationSpec(
BucketSortPipelineAggregationBuilder.NAME,
BucketSortPipelineAggregationBuilder::new,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
* Side Public License, v 1.
*/

package org.elasticsearch.search.aggregations.pipeline;
package org.elasticsearch.aggregations.pipeline;

import org.elasticsearch.Version;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.aggregations.pipeline.AbstractPipelineAggregationBuilder;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;

Expand Down Expand Up @@ -41,10 +43,6 @@ public BucketSelectorPipelineAggregationBuilder(String name, Map<String, String>
this.script = script;
}

public BucketSelectorPipelineAggregationBuilder(String name, Script script, String... bucketsPaths) {
this(name, convertToBucketsPathMap(bucketsPaths), script);
}

/**
* Read from a stream.
*/
Expand All @@ -62,14 +60,6 @@ protected void doWriteTo(StreamOutput out) throws IOException {
gapPolicy.writeTo(out);
}

private static Map<String, String> convertToBucketsPathMap(String[] bucketsPaths) {
Map<String, String> bucketsPathsMap = new HashMap<>();
for (int i = 0; i < bucketsPaths.length; i++) {
bucketsPathsMap.put("_value" + i, bucketsPaths[i]);
}
return bucketsPathsMap;
}

/**
* Sets the gap policy to use for this aggregation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
* Side Public License, v 1.
*/

package org.elasticsearch.search.aggregations.pipeline;
package org.elasticsearch.aggregations.pipeline;

import org.elasticsearch.script.BucketAggregationSelectorScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.aggregations.AggregationReduceContext;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@
* Side Public License, v 1.
*/

package org.elasticsearch.search.aggregations.pipeline;
package org.elasticsearch.aggregations.pipeline;

import org.elasticsearch.aggregations.AggregationsPlugin;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.hamcrest.CoreMatchers.equalTo;

public class BucketSelectorTests extends BasePipelineAggregationTestCase<BucketSelectorPipelineAggregationBuilder> {
public class BucketSelectorAggregationBuilderTests extends BasePipelineAggregationTestCase<BucketSelectorPipelineAggregationBuilder> {

@Override
protected List<SearchPlugin> plugins() {
return List.of(new AggregationsPlugin());
}

@Override
protected BucketSelectorPipelineAggregationBuilder createTestAggregatorFactory() {
Expand Down
Loading

0 comments on commit 76bd44f

Please sign in to comment.