Create default for ExecutableScript#unwrap
Tons of scripts just return the variable they are passed and that is the most intuitive behavior so that may as well be the default implementation.
This commit is contained in:
parent
2249a640bb
commit
e1e73d9914
|
@ -24,9 +24,4 @@ public abstract class AbstractExecutableScript implements ExecutableScript {
|
|||
@Override
|
||||
public void setNextVar(String name, Object value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -32,8 +32,12 @@ public interface ExecutableScript {
|
|||
Object run();
|
||||
|
||||
/**
|
||||
* Unwraps a possible script value. For example, when passing vars and expecting the returned value to
|
||||
* be part of the vars.
|
||||
* Unwraps a possible script value. For example, when passing vars and
|
||||
* expecting the returned value to be part of the vars. Javascript and
|
||||
* Python need this but other scripting engines just return the values
|
||||
* passed in.
|
||||
*/
|
||||
Object unwrap(Object value);
|
||||
default Object unwrap(Object value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1447,12 +1447,6 @@ public class DateHistogramIT extends ESIntegTestCase {
|
|||
final LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context);
|
||||
|
||||
return new LeafSearchScript() {
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNextVar(String name, Object value) {
|
||||
}
|
||||
|
|
|
@ -388,12 +388,6 @@ public class AvgIT extends AbstractNumericTestCase {
|
|||
final LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context);
|
||||
|
||||
return new LeafSearchScript() {
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNextVar(String name, Object value) {
|
||||
}
|
||||
|
@ -526,12 +520,6 @@ public class AvgIT extends AbstractNumericTestCase {
|
|||
final LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context);
|
||||
|
||||
return new LeafSearchScript() {
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNextVar(String name, Object value) {
|
||||
vars.put(name, value);
|
||||
|
|
|
@ -384,12 +384,6 @@ public class SumIT extends AbstractNumericTestCase {
|
|||
final LeafSearchLookup leafLookup = lookup.getLeafSearchLookup(context);
|
||||
|
||||
return new LeafSearchScript() {
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNextVar(String name, Object value) {
|
||||
}
|
||||
|
|
|
@ -33,10 +33,10 @@ import org.elasticsearch.client.transport.NoNodeAvailableException;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.MergePolicyConfig;
|
||||
import org.elasticsearch.index.VersionType;
|
||||
import org.elasticsearch.index.engine.DocumentMissingException;
|
||||
import org.elasticsearch.index.engine.VersionConflictEngineException;
|
||||
import org.elasticsearch.index.MergePolicyConfig;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
|
@ -154,12 +154,6 @@ public class UpdateIT extends ESIntegTestCase {
|
|||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -245,12 +239,6 @@ public class UpdateIT extends ESIntegTestCase {
|
|||
source.put(field, currentValue.longValue() + inc.longValue());
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -336,12 +324,6 @@ public class UpdateIT extends ESIntegTestCase {
|
|||
source.put("balance", oldBalance.intValue() - deduction);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -428,12 +410,6 @@ public class UpdateIT extends ESIntegTestCase {
|
|||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -19,14 +19,14 @@
|
|||
|
||||
package org.elasticsearch.script.expression;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.expressions.Expression;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.ScriptException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A bridge to evaluate an {@link Expression} against a map of variables in the context
|
||||
* of an {@link ExecutableScript}.
|
||||
|
@ -90,9 +90,4 @@ public class ExpressionExecutableScript implements ExecutableScript {
|
|||
throw new ScriptException("Error evaluating " + compiledScript, exception);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
|
||||
package org.elasticsearch.script.expression;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.expressions.Bindings;
|
||||
import org.apache.lucene.expressions.Expression;
|
||||
import org.apache.lucene.expressions.SimpleBindings;
|
||||
|
@ -32,10 +36,6 @@ import org.elasticsearch.script.LeafSearchScript;
|
|||
import org.elasticsearch.script.ScriptException;
|
||||
import org.elasticsearch.script.SearchScript;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A bridge to evaluate an {@link Expression} against {@link Bindings} in the context
|
||||
* of a {@link SearchScript}.
|
||||
|
@ -89,9 +89,6 @@ class ExpressionSearchScript implements SearchScript {
|
|||
@Override
|
||||
public double runAsDouble() { return evaluate(); }
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) { return value; }
|
||||
|
||||
@Override
|
||||
public void setDocument(int d) {
|
||||
docid = d;
|
||||
|
|
|
@ -19,10 +19,14 @@
|
|||
|
||||
package org.elasticsearch.script.groovy;
|
||||
|
||||
import groovy.lang.Binding;
|
||||
import groovy.lang.GroovyClassLoader;
|
||||
import groovy.lang.GroovyCodeSource;
|
||||
import groovy.lang.Script;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
|
@ -56,14 +60,10 @@ import org.elasticsearch.script.SearchScript;
|
|||
import org.elasticsearch.search.lookup.LeafSearchLookup;
|
||||
import org.elasticsearch.search.lookup.SearchLookup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import groovy.lang.Binding;
|
||||
import groovy.lang.GroovyClassLoader;
|
||||
import groovy.lang.GroovyCodeSource;
|
||||
import groovy.lang.Script;
|
||||
|
||||
/**
|
||||
* Provides the infrastructure for Groovy as a scripting language for Elasticsearch
|
||||
|
@ -333,12 +333,6 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri
|
|||
public double runAsDouble() {
|
||||
return ((Number) run()).doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,12 @@
|
|||
*/
|
||||
package org.elasticsearch.script.mustache;
|
||||
|
||||
import com.github.mustachejava.Mustache;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.SpecialPermission;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
|
@ -34,11 +39,7 @@ import org.elasticsearch.script.ScriptException;
|
|||
import org.elasticsearch.script.SearchScript;
|
||||
import org.elasticsearch.search.lookup.SearchLookup;
|
||||
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import com.github.mustachejava.Mustache;
|
||||
|
||||
/**
|
||||
* Main entry point handling template registration, compilation and
|
||||
|
@ -174,10 +175,5 @@ public class MustacheScriptEngineService extends AbstractComponent implements Sc
|
|||
}
|
||||
return result.bytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unwrap(Object value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,15 +19,15 @@
|
|||
|
||||
package org.elasticsearch.plan.a;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.LeafSearchScript;
|
||||
import org.elasticsearch.script.ScoreAccessor;
|
||||
import org.elasticsearch.search.lookup.LeafSearchLookup;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ScriptImpl can be used as either an {@link ExecutableScript} or a {@link LeafSearchScript}
|
||||
* to run a previously compiled Plan A script.
|
||||
|
@ -114,16 +114,6 @@ final class ScriptImpl implements ExecutableScript, LeafSearchScript {
|
|||
return ((Number)run()).longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method has no effect in Plan A.
|
||||
* @param value The value to unwrap.
|
||||
* @return The value passed in.
|
||||
*/
|
||||
@Override
|
||||
public Object unwrap(final Object value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scorer to be accessible within a script.
|
||||
* @param scorer The scorer used for a search.
|
||||
|
|
Loading…
Reference in New Issue