Adaptive radix tree aggregate matching #2
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces aggregate adaptive radix tree matching for expressions. The general idea here is to ignore expressions that don't matter given input data. For example:
event.data.account_id = $foo
)In order to do that, we must parse the CEL expression into its AST, normalize into a canonical representation, then parse each operand into an aggregate tree for matching.
Each expression is broken down into groups. For example:
Is broken down into a single matching group containing two predicate operators for A and B. For each ident matching strings, ("a" and "b"), we create a new adaptive radix tree matching the given literal value.
When an event is received, we iterate through the keys in the given event. If there's an ART for the key in the event, we match the event's data against the tree. This returns potential expressions to evaluate.
From there, we evaluate only all matched expressions (plus any expressions that cannot be evaluated by aggregate trees). This cuts down the number of expressions evaluated by orders of magnitude.