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

Optimize filter expression script #707

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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