Skip to content

Commit 9d92a87

Browse files
rationullcolings86
authored andcommitted
Remove support for deprecated params._agg/_aggs for scripted metric aggregations (#32979)
1 parent 19ef41e commit 9d92a87

File tree

11 files changed

+20
-366
lines changed

11 files changed

+20
-366
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,6 @@ class BuildPlugin implements Plugin<Project> {
802802
systemProperty 'tests.task', path
803803
systemProperty 'tests.security.manager', 'true'
804804
systemProperty 'jna.nosys', 'true'
805-
// TODO: remove this deprecation compatibility setting for 7.0
806-
systemProperty 'es.aggregations.enable_scripted_metric_agg_param', 'false'
807805
systemProperty 'compiler.java', project.ext.compilerJavaVersion.getMajorVersion()
808806
if (project.ext.inFipsJvm) {
809807
systemProperty 'runtime.java', project.ext.runtimeJavaVersion.getMajorVersion() + "FIPS"

docs/build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ integTestCluster {
4141
// TODO: remove this for 7.0, this exists to allow the doc examples in 6.x to continue using the defaults
4242
systemProperty 'es.scripting.use_java_time', 'false'
4343
systemProperty 'es.scripting.update.ctx_in_params', 'false'
44-
45-
// TODO: remove this deprecation compatibility setting for 7.0
46-
systemProperty 'es.aggregations.enable_scripted_metric_agg_param', 'false'
4744
}
4845

4946
// remove when https://github.com/elastic/elasticsearch/issues/31305 is fixed

docs/reference/migration/migrate_7_0/aggregations.asciidoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,3 @@ has been removed. `missing_bucket` should be used instead.
2121
The object used to share aggregation state between the scripts in a Scripted Metric
2222
Aggregation is now a variable called `state` available in the script context, rather than
2323
being provided via the `params` object as `params._agg`.
24-
25-
The old `params._agg` variable is still available as well.

server/build.gradle

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,3 @@ if (isEclipse == false || project.path == ":server-tests") {
346346
check.dependsOn integTest
347347
integTest.mustRunAfter test
348348
}
349-
350-
// TODO: remove these compatibility tests in 7.0
351-
additionalTest('testScriptedMetricAggParamsV6Compatibility') {
352-
include '**/ScriptedMetricAggregatorAggStateV6CompatTests.class'
353-
include '**/InternalScriptedMetricAggStateV6CompatTests.class'
354-
systemProperty 'es.aggregations.enable_scripted_metric_agg_param', 'true'
355-
}
356-
357-
test {
358-
// these are tested explicitly in separate test tasks
359-
exclude '**/ScriptedMetricAggregatorAggStateV6CompatTests.class'
360-
exclude '**/InternalScriptedMetricAggStateV6CompatTests.class'
361-
}

server/src/main/java/org/elasticsearch/script/ScriptedMetricAggContexts.java

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import org.apache.lucene.index.LeafReaderContext;
2323
import org.apache.lucene.search.Scorer;
2424
import org.elasticsearch.ElasticsearchException;
25-
import org.elasticsearch.common.logging.DeprecationLogger;
26-
import org.elasticsearch.common.logging.Loggers;
2725
import org.elasticsearch.index.fielddata.ScriptDocValues;
2826
import org.elasticsearch.search.lookup.LeafSearchLookup;
2927
import org.elasticsearch.search.lookup.SearchLookup;
@@ -33,30 +31,11 @@
3331
import java.util.Map;
3432

3533
public class ScriptedMetricAggContexts {
36-
private static final DeprecationLogger DEPRECATION_LOGGER =
37-
new DeprecationLogger(Loggers.getLogger(ScriptedMetricAggContexts.class));
38-
39-
// Public for access from tests
40-
public static final String AGG_PARAM_DEPRECATION_WARNING =
41-
"params._agg/_aggs for scripted metric aggregations are deprecated, use state/states (not in params) instead. " +
42-
"Use -Des.aggregations.enable_scripted_metric_agg_param=false to disable.";
43-
44-
public static boolean deprecatedAggParamEnabled() {
45-
boolean enabled = Boolean.parseBoolean(
46-
System.getProperty("es.aggregations.enable_scripted_metric_agg_param", "true"));
47-
48-
if (enabled) {
49-
DEPRECATION_LOGGER.deprecatedAndMaybeLog("enable_scripted_metric_agg_param", AGG_PARAM_DEPRECATION_WARNING);
50-
}
51-
52-
return enabled;
53-
}
54-
5534
private abstract static class ParamsAndStateBase {
5635
private final Map<String, Object> params;
57-
private final Object state;
36+
private final Map<String, Object> state;
5837

59-
ParamsAndStateBase(Map<String, Object> params, Object state) {
38+
ParamsAndStateBase(Map<String, Object> params, Map<String, Object> state) {
6039
this.params = params;
6140
this.state = state;
6241
}
@@ -71,14 +50,14 @@ public Object getState() {
7150
}
7251

7352
public abstract static class InitScript extends ParamsAndStateBase {
74-
public InitScript(Map<String, Object> params, Object state) {
53+
public InitScript(Map<String, Object> params, Map<String, Object> state) {
7554
super(params, state);
7655
}
7756

7857
public abstract void execute();
7958

8059
public interface Factory {
81-
InitScript newInstance(Map<String, Object> params, Object state);
60+
InitScript newInstance(Map<String, Object> params, Map<String, Object> state);
8261
}
8362

8463
public static String[] PARAMETERS = {};
@@ -89,7 +68,7 @@ public abstract static class MapScript extends ParamsAndStateBase {
8968
private final LeafSearchLookup leafLookup;
9069
private Scorer scorer;
9170

92-
public MapScript(Map<String, Object> params, Object state, SearchLookup lookup, LeafReaderContext leafContext) {
71+
public MapScript(Map<String, Object> params, Map<String, Object> state, SearchLookup lookup, LeafReaderContext leafContext) {
9372
super(params, state);
9473

9574
this.leafLookup = leafContext == null ? null : lookup.getLeafSearchLookup(leafContext);
@@ -131,22 +110,22 @@ public interface LeafFactory {
131110
}
132111

133112
public interface Factory {
134-
LeafFactory newFactory(Map<String, Object> params, Object state, SearchLookup lookup);
113+
LeafFactory newFactory(Map<String, Object> params, Map<String, Object> state, SearchLookup lookup);
135114
}
136115

137116
public static String[] PARAMETERS = new String[] {};
138117
public static ScriptContext<Factory> CONTEXT = new ScriptContext<>("aggs_map", Factory.class);
139118
}
140119

141120
public abstract static class CombineScript extends ParamsAndStateBase {
142-
public CombineScript(Map<String, Object> params, Object state) {
121+
public CombineScript(Map<String, Object> params, Map<String, Object> state) {
143122
super(params, state);
144123
}
145124

146125
public abstract Object execute();
147126

148127
public interface Factory {
149-
CombineScript newInstance(Map<String, Object> params, Object state);
128+
CombineScript newInstance(Map<String, Object> params, Map<String, Object> state);
150129
}
151130

152131
public static String[] PARAMETERS = {};

server/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetric.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ public InternalAggregation doReduce(List<InternalAggregation> aggregations, Redu
9595
params.putAll(firstAggregation.reduceScript.getParams());
9696
}
9797

98-
// Add _aggs to params map for backwards compatibility (redundant with a context variable on the ReduceScript created below).
99-
if (ScriptedMetricAggContexts.deprecatedAggParamEnabled()) {
100-
params.put("_aggs", aggregationObjects);
101-
}
102-
10398
ScriptedMetricAggContexts.ReduceScript.Factory factory = reduceContext.scriptService().compile(
10499
firstAggregation.reduceScript, ScriptedMetricAggContexts.ReduceScript.CONTEXT);
105100
ScriptedMetricAggContexts.ReduceScript script = factory.newInstance(params, aggregationObjects);

server/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public class ScriptedMetricAggregator extends MetricsAggregator {
4141
private final ScriptedMetricAggContexts.MapScript.LeafFactory mapScript;
4242
private final ScriptedMetricAggContexts.CombineScript combineScript;
4343
private final Script reduceScript;
44-
private Object aggState;
44+
private Map<String, Object> aggState;
4545

4646
protected ScriptedMetricAggregator(String name, ScriptedMetricAggContexts.MapScript.LeafFactory mapScript, ScriptedMetricAggContexts.CombineScript combineScript,
47-
Script reduceScript, Object aggState, SearchContext context, Aggregator parent,
47+
Script reduceScript, Map<String, Object> aggState, SearchContext context, Aggregator parent,
4848
List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
4949
throws IOException {
5050
super(name, context, parent, pipelineAggregators, metaData);

server/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorFactory.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,7 @@ public Aggregator createInternal(Aggregator parent, boolean collectsFromSingleBu
8080
aggParams = new HashMap<>();
8181
}
8282

83-
// Add _agg to params map for backwards compatibility (redundant with context variables on the scripts created below).
84-
// When this is removed, aggState (as passed to ScriptedMetricAggregator) can be changed to Map<String, Object>, since
85-
// it won't be possible to completely replace it with another type as is possible when it's an entry in params.
86-
Object aggState = new HashMap<String, Object>();
87-
if (ScriptedMetricAggContexts.deprecatedAggParamEnabled()) {
88-
if (aggParams.containsKey("_agg") == false) {
89-
// Add _agg if it wasn't added manually
90-
aggParams.put("_agg", aggState);
91-
} else {
92-
// If it was added manually, also use it for the agg context variable to reduce the likelihood of
93-
// weird behavior due to multiple different variables.
94-
aggState = aggParams.get("_agg");
95-
}
96-
}
83+
Map<String, Object> aggState = new HashMap<String, Object>();
9784

9885
final ScriptedMetricAggContexts.InitScript initScript = this.initScript.newInstance(
9986
mergeParams(aggParams, initScriptParams), aggState);

server/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetricAggStateV6CompatTests.java

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)