private TemplateDruidQuery buildOuterQuery(String metricDictionary,MetricField sourceMetric,TemplateDruidQuery innerQuery){
  Aggregation sum=createSummingAggregator(sourceMetric);
  Set<Aggregation> outerAggs=new LinkedHashSet<>(Arrays.asList(sum,COUNT_OUTER));
  FieldAccessorPostAggregation sumPost=new FieldAccessorPostAggregation(sum);
  PostAggregation average=new ArithmeticPostAggregation(metricDictionary,DIVIDE,Arrays.asList(sumPost,COUNT_FIELD_OUTER));
  Set<PostAggregation> outerPostAggs=Collections.singleton(average);
  return new TemplateDruidQuery(outerAggs,outerPostAggs,innerQuery);
}

private TemplateDruidQuery buildOuterQuery ( String metricDictionary , MetricField sourceMetric , TemplateDruidQuery innerQuery ) { Aggregation sum = createSummingAggregator ( sourceMetric ) ; Set < Aggregation > outerAggs = new LinkedHashSet < > ( Arrays . asList ( sum , COUNT_OUTER ) ) ; FieldAccessorPostAggregation sumPost = new FieldAccessorPostAggregation ( sum ) ; PostAggregation average = new ArithmeticPostAggregation ( metricDictionary , DIVIDE , Arrays . asList ( sumPost , COUNT_FIELD_OUTER ) ) ; Set < PostAggregation > outerPostAggs = Collections . singleton ( average ) ; return new TemplateDruidQuery ( outerAggs , outerPostAggs , innerQuery ) ; }
build the outer query for the average . it will have a sum , a count , and a post agg to divide them .
