Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhaul function/param descriptors and precompute constant function …
…arguments To avoid reevaluating function arguments which never change for each message and are potentially expensive to calculate (either because their expression tree is deep or the function needs to construct other objects) the Function interface now contains a callback to provide precomputed values for each constant argument. This callback is only invoked for provably constant expressions, so it is safe to implement for any function. The recommended way is to inherit from AbstractFunction<T> which implements the straightforward precompute function by simply memoizing the evaluated value. For special cases, like the RegexMatch function, which precomputes a Pattern.compile from a constant parameter descriptors take a java.util.function.Function now, which gets invoked with the computed value. The default is the identity function. Parameter descriptors are now responsible for evaluating argument expressions, and are fully generic.
- Loading branch information
Showing
27 changed files
with
479 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/org/graylog/plugins/pipelineprocessor/ast/functions/AbstractFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.graylog.plugins.pipelineprocessor.ast.functions; | ||
|
||
import org.graylog.plugins.pipelineprocessor.EvaluationContext; | ||
import org.graylog.plugins.pipelineprocessor.ast.expressions.Expression; | ||
|
||
/** | ||
* Helper Function implementation which evaluates and memoizes all constant FunctionArgs. | ||
* | ||
* @param <T> the return type | ||
*/ | ||
public abstract class AbstractFunction<T> implements Function<T> { | ||
|
||
@Override | ||
public Object preComputeConstantArgument(FunctionArgs args, String name, Expression arg) { | ||
return arg.evaluate(EvaluationContext.emptyContext()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.