You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2019/06/07 15:43:25 UTC

[GitHub] [incubator-druid] jmarxuach commented on issue #7849: Geometric mean calculation

jmarxuach commented on issue #7849: Geometric mean calculation
URL: https://github.com/apache/incubator-druid/issues/7849#issuecomment-499936073
 
 
   After some research, I found a solution.
   
   I enabled javascript and i create an aggregator and a post-aggregator .
   
   Agregator SUM_LOG =  ( log(n1)+log(n2)+log(n3)+....) 
   
   ```javascript
   
   {
     "type": "javascript",
     "name": "SUM_LOG",
     "fieldNames": ["column"],
     "fnAggregate" : "function(current, column)      { 
                    if (a>0)  return  current + (Math.log(column)/ Math.log(10)); else return 0;
      }",
     "fnCombine"   : "function(partialA, partialB) { return partialA + partialB; }",
     "fnReset"     : "function()                   { return 0; }"
   }
   ```
   Then I created a post-aggregator : 10^(logSum/count)
   
   ```javascript
   {
     "type": "javascript",
     "name": "GEO_MEAN",
     "fieldNames" : ["SUM_LOG", "count"],
     "function": "function(SUM_LOG, count) { return Math.pow(10, (SUM_LOG/count)); }"
   }
   ```
   
   And that's it !! My feature proposal a sumlog is not needed if you enable javascript. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org