Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Optimize filter expression script (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
penghuo authored Aug 25, 2020
1 parent 684690a commit c66ba42
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReferenceExpression> fields;

public ExpressionFilterScript(Expression expression,
SearchLookup lookup,
LeafReaderContext context,
Map<String, Object> params) {
super(params, lookup, context);
this.expression = expression;
this.fields = AccessController.doPrivileged((PrivilegedAction<Set<ReferenceExpression>>) () ->
extractFields(expression));
this.valueFactory =
AccessController.doPrivileged(
(PrivilegedAction<ElasticsearchExprValueFactory>) () -> buildValueFactory(fields));
}

@Override
public boolean execute() {
// Check current script are not being called by unprivileged code.
SpecialPermission.check();

return AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
Set<ReferenceExpression> fields = extractFields(expression);
ElasticsearchExprValueFactory valueFactory = buildValueFactory(fields);
Environment<Expression, ExprValue> valueEnv = buildValueEnv(fields, valueFactory);
ExprValue result = evaluateExpression(valueEnv);
return (Boolean) result.value();
Expand Down

0 comments on commit c66ba42

Please sign in to comment.