Year Over Year calculation support using JavaScript (post)aggregator


Is it possible to have an aggregator/calculation that requires access to previous time period or even other dimension value for the same metric.

YoY is one example where we need access to a different time period for the same metric. (Current Year Revenue - Last Year Revenue).

Thanks & Regards


Can your client layer issue two queries to perform the calculation versus one query in Druid?

That’s a worst case scenario, in case there are no other options available with a single call. We are willing to even write an extension if it would be possible.


Hey Gap,

Could you please give some insight into why two queries is a worst case scenario? I’m asking because there’s a few situations in Druid where the best approach is to make multiple queries, and so far we’ve assumed that would not generally be a big problem for users.

To your specific question, I think there are two easiest solutions.

  1. in the upcoming 0.9.2 you could use an approach with two time-filtered aggregators and a post-aggregator:

  2. in current versions, time-filtered aggregators don’t exist, but I think you can do something similar with two javascript aggregators reading the “__time” column and your metric column, at some performance cost. The post-aggregator would be the same.