elasticsearch icon indicating copy to clipboard operation
elasticsearch copied to clipboard

[ES|QL] weighted_avg

Open fang-xing-esql opened this issue 1 year ago • 5 comments

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.

fang-xing-esql avatar Jun 20 '24 17:06 fang-xing-esql

Documentation preview:

github-actions[bot] avatar Jun 20 '24 17:06 github-actions[bot]

Hi @fang-xing-esql, I've created a changelog YAML for you.

elasticsearchmachine avatar Jun 20 '24 17:06 elasticsearchmachine

The weighted_avg is similar to avg, it is a SurrogateExpression, is rewritten with existing functions.

fang-xing-esql avatar Jun 20 '24 17:06 fang-xing-esql

@elasticmachine update branch

astefan avatar Jun 21 '24 06:06 astefan

Pinging @elastic/es-analytical-engine (Team:Analytics)

elasticsearchmachine avatar Jun 24 '24 03:06 elasticsearchmachine

Pinging @elastic/kibana-esql (ES|QL-ui)

elasticsearchmachine avatar Jul 02 '24 18:07 elasticsearchmachine