Custom Java Script Aggregators or Derived Metrices

Hi,
I have created two metrices in Druid at the time of ingestion.

1. {

“type” : “doubleSum”,

“name” : “buyer_bid”,

“fieldName” : “buyer_bid”

}

2. {

“type” : “doubleSum”,

“name” : “impressions”,

“fieldName” : “impressions”

}

I want to add another metric Buyer_Bid at the time of ingestion which should perform the following functionality

**Buyer_Bid = ****sum(buyer_bid) / sum(impressions) **

How do I perform this using J**ava Script Aggregator ** (http://druid.io/docs/latest/querying/aggregations.html) and what should the ingestion spec look like corresponding to this metric. ??

The Java Script aggregator accepts a function fnCombine ****which tells how the aggregations should be carried out across different rows which is somewhat different from what i want.

eg:

{
  "type": "javascript",
  "name": "sum(log(x)*y) + 10",
  "fieldNames": ["x", "y"],
  "fnAggregate" : "function(current, a, b)      { return current + (Math.log(a) * b); }",
  "fnCombine"   : "function(partialA, partialB) { return partialA + partialB; }",
  "fnReset"     : "function()                   { return 10; }"

Can anyone help ??

Hey Bikash,

You could do that as a post-aggregation at query time, on the two columns you already have. You can’t define post-aggregations at ingestion time.

Hey Glan.,
Thanks for the reply.

I am using pivot with druid as base. and i wanted to do post aggregations with pivot.

Hi Bikash,

You might be interested to read: https://github.com/implydata/pivot/blob/master/docs/configuration.md

Specifically the section: https://github.com/implydata/pivot/blob/master/docs/configuration.md#custom-aggregations would be specifically relevant to you.

For any more questions about Pivot use please drop by the Imply User Group https://groups.google.com/forum/#!forum/imply-user-group

Best regards,

Vadim