Skip to content

Commit 8d2fc53

Browse files
committed
Removing params from execute
1 parent f55689d commit 8d2fc53

File tree

6 files changed

+14
-17
lines changed

6 files changed

+14
-17
lines changed

server/src/main/java/org/elasticsearch/ingest/ConditionalProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ boolean evaluate(IngestDocument ingestDocument) {
150150
IngestConditionalScript.Factory factory = scriptService.compile(condition, IngestConditionalScript.CONTEXT);
151151
script = factory.newInstance(condition.getParams(), ctxMapWrapper);
152152
}
153-
ctxMapWrapper.setCtxMap(ingestDocument.getCtxMap());
153+
ctxMapWrapper.setCtxMap(new UnmodifiableIngestData(new DynamicMap(ingestDocument.getSourceAndMetadata(), FUNCTIONS)));
154154
try {
155-
return script.execute(new UnmodifiableIngestData(new DynamicMap(ingestDocument.getSourceAndMetadata(), FUNCTIONS)));
155+
return script.execute();
156156
} finally {
157157
ctxMapWrapper.clearCtxMap();
158158
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@
99

1010
package org.elasticsearch.script;
1111

12+
import java.util.Map;
13+
1214
/**
1315
* A wrapper for a {@link CtxMap} that allows for ad-hoc setting for script execution.
1416
* This allows for precompilation of scripts that can be executed with different contexts.
1517
* The wrapped {@link CtxMap} should be cleared after use to avoid leaks.
1618
*/
1719
public class CtxMapWrapper {
18-
private CtxMap<?> ctxMap;
20+
private Map<String, Object> ctxMap;
1921

20-
public CtxMap<?> getCtxMap() {
22+
public Map<String, Object> getCtxMap() {
2123
if (ctxMap == null) {
2224
throw new IllegalStateException("CtxMap is not set");
2325
}
2426
return ctxMap;
2527
}
2628

27-
public void setCtxMap(CtxMap<?> ctxMap) {
29+
public void setCtxMap(Map<String, Object> ctxMap) {
2830
this.ctxMap = ctxMap;
2931
}
3032

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
public abstract class IngestConditionalScript extends SourceMapFieldScript {
2222

23-
public static final String[] PARAMETERS = { "runtime-params" };
23+
public static final String[] PARAMETERS = {};
2424

2525
/** The context used to compile {@link IngestConditionalScript} factories. */
2626
public static final ScriptContext<Factory> CONTEXT = new ScriptContext<>(
@@ -45,7 +45,7 @@ public Map<String, Object> getParams() {
4545
return params;
4646
}
4747

48-
public abstract boolean execute(Map<String, Object> params);
48+
public abstract boolean execute();
4949

5050
public interface Factory {
5151
IngestConditionalScript newInstance(Map<String, Object> params, CtxMapWrapper ctxMapWrapper);

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ public Map<String, Object> getCtx() {
2929
return ctxMapWrapper.getCtxMap();
3030
}
3131

32-
/** Return the metadata for this script */
33-
public Metadata metadata() {
34-
return ctxMapWrapper.getCtxMap().getMetadata();
35-
}
36-
3732
public SourceMapField field(String path) {
38-
return new SourceMapField(path, () -> ctxMapWrapper.getCtxMap().getSource());
33+
return new SourceMapField(path, ctxMapWrapper::getCtxMap);
3934
}
4035
}

server/src/test/java/org/elasticsearch/ingest/ConditionalProcessorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public void testRuntimeCompileError() {
208208
} else {
209209
return (params, ctxMap) -> new IngestConditionalScript(params, ctxMap) {
210210
@Override
211-
public boolean execute(Map<String, Object> params) {
211+
public boolean execute() {
212212
return false;
213213
}
214214
};
@@ -228,7 +228,7 @@ public void testRuntimeError() {
228228
IngestConditionalScript.CONTEXT,
229229
code -> (params, ctxMapWrapper) -> new IngestConditionalScript(params, ctxMapWrapper) {
230230
@Override
231-
public boolean execute(Map<String, Object> params) {
231+
public boolean execute() {
232232
throw new IllegalArgumentException("runtime problem");
233233
}
234234
},

test/framework/src/main/java/org/elasticsearch/script/MockScriptEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ public void execute() {
174174
ctxMapWrapper
175175
) {
176176
@Override
177-
public boolean execute(Map<String, Object> params) {
178-
return (boolean) script.apply(params);
177+
public boolean execute() {
178+
return (boolean) script.apply(ctxMapWrapper.getCtxMap());
179179
}
180180
};
181181
return context.factoryClazz.cast(factory);

0 commit comments

Comments
 (0)