title: Using Javascript aggregation in druid queries
body: <p>I am trying to write javascript aggregator for my druid queries. i need to to calculate average of a metric "Base_SalesRank".<br>
  So far i have been able to this by writing:</p>
  
  <pre><code> {
     "queryType": "groupBy",
     "dataSource": "marketdata",
     "granularity": "all",
  
     "dimensions" : ["Item"],
     "filter": { "type": "and", "fields" : [{"type": "selector", "dimension": "Item", "value": "MN10CESWW"}]},
     "intervals": ["2018-06-28T00:00Z/2018-07-04T00:00Z"],
    "aggregations" : [
      { "type" : "count", "name" : "rows" },
      { "type" : "doubleSum", "name" : "Base_SalesRank", "fieldName" : "Base_SalesRank" }
    ],
    "postAggregations" : [{
     "type": "javascript",
    "name": "Target DOS Average",
    "fieldNames": ["Base_SalesRank", "rows"],
      "function": "function(Base_SalesRank, rows) {return Base_SalesRank/ rows;}" 
    }]
  }
  </code></pre>
  
  <p>But I noticed that many values in Base_SalesRank is 0.</p>
  
  <pre><code>[ { 
    "timestamp" : "2018-06-28T05:06:03.000Z",
    "result" : {
      "pagingIdentifiers" : {
        "marketdata_2018-06-28T00:00:00.000Z_2018-06-29T00:00:00.000Z_2018-07-06T08:11:02.499Z" : 3
      },
      "dimensions" : [ "Item" ],
      "metrics" : [ "Base_SalesRank" ],
      "events" : [ {
        "segmentId" : "marketdata_2018-06-28T00:00:00.000Z_2018-06-29T00:00:00.000Z_2018-07-06T08:11:02.499Z",
        "offset" : 0,
        "event" : {
          "timestamp" : "2018-06-28T07:10:02.000Z",
          "Item" : "MN10CESWW",
          "Base_SalesRank" : 0
        }
      },
   {
        "segmentId" : "marketdata_2018-06-28T00:00:00.000Z_2018-06-29T00:00:00.000Z_2018-07-06T08:11:02.499Z",
        "offset" : 3,
        "event" : {
          "timestamp" : "2018-06-28T07:20:21.000Z",
          "Item" : "MN10CESWW",
          "Base_SalesRank" : 5558
        }
      } ]
    }
  } ]
  </code></pre>
  
  <p>So i am not getting true average. Now i need to weed out these 0 values and then calucate average. We can do this by using filters</p>
  
  <pre><code>{"type": "not", "field": {"type": "selector", "dimension": "Base_SalesRank", "value": "0"}}
  </code></pre>
  
  <p>But I have constraint that I have to perform this filter operation inside the javascript function only.</p>