diff --git a/elasticsearch/src/main/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/storage/script/filter/ExpressionFilterScript.java b/elasticsearch/src/main/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/storage/script/filter/ExpressionFilterScript.java index 31908cd1f4..08cb490080 100644 --- a/elasticsearch/src/main/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/storage/script/filter/ExpressionFilterScript.java +++ b/elasticsearch/src/main/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/storage/script/filter/ExpressionFilterScript.java @@ -56,22 +56,34 @@ class ExpressionFilterScript extends FilterScript { */ private final Expression expression; + /** + * ElasticsearchExprValueFactory. + */ + @EqualsAndHashCode.Exclude + private final ElasticsearchExprValueFactory valueFactory; + + /** + * Reference Fields. + */ + @EqualsAndHashCode.Exclude + private final Set fields; + public ExpressionFilterScript(Expression expression, SearchLookup lookup, LeafReaderContext context, Map params) { super(params, lookup, context); this.expression = expression; + this.fields = AccessController.doPrivileged((PrivilegedAction>) () -> + extractFields(expression)); + this.valueFactory = + AccessController.doPrivileged( + (PrivilegedAction) () -> buildValueFactory(fields)); } @Override public boolean execute() { - // Check current script are not being called by unprivileged code. - SpecialPermission.check(); - return AccessController.doPrivileged((PrivilegedAction) () -> { - Set fields = extractFields(expression); - ElasticsearchExprValueFactory valueFactory = buildValueFactory(fields); Environment valueEnv = buildValueEnv(fields, valueFactory); ExprValue result = evaluateExpression(valueEnv); return (Boolean) result.value();