Why does druid call post-agg functions before calling finalizeComputation of AggregatorFactory


We have some custom aggregators (TDigest based sketch implementation for histogram calculation) internally that returns intermediate mergable objects from implementation of get method of the Aggregator interface. The intermediate mergable objects are converted into final result objects when the finalizeComputation method of the AggregatorFactory interface’s implementation is called. Our assumption from the documentation of the method and post-aggregator was that any post-aggregator will only be called after the final aggregator results are computed. However in practice we have noticed that it is not the case. The code seem to just call the get method on aggregator and pass its result to postaggregator. This forces us to write custom postaggregator and pretty much makes javascript postaggregator useless in absence of a custom postaggregator implementation.

Questions I have:

  • Why does postagg receive intermediate mergable instances instead of final resultant instance of the aggregator?
  • If the above choice is not a bug, how are users expected to use javascript postaggregator on aggregators that have a complex object being returned from intermediate get method which is different then the final agg result instance?