elasticsearch
elasticsearch copied to clipboard
[ES|QL] weighted_avg
Add weighted_avg function for #109940
We need two rules to be able to support weighted_avg - ReplaceStatsNestedExpressionWithEval and SubstituteSurrogates.
SubstituteSurrogates rewrites weighted_avg(value, weight) to sum(value*weight)/sum(weight), and ReplaceStatsNestedExpressionWithEval rewrite sum(value*weight) to eval f=value*weight and then sum(f). And we want ReplaceStatsNestedExpressionWithEval to be applied after SubstituteSurrogates. Today ReplaceStatsNestedExpressionWithEval is applied before SubstituteSurrogates, and they are applied only once. Switching the order causes some test failures, so a separate batch is created for the 4 rules related to stats transformation, so that they can be applied multiple times together.
Hi @fang-xing-esql, I've created a changelog YAML for you.
The weighted_avg is similar to avg, it is a SurrogateExpression, is rewritten with existing functions.
@elasticmachine update branch
Pinging @elastic/es-analytical-engine (Team:Analytics)
Pinging @elastic/kibana-esql (ES|QL-ui)