public TemplateDruidQuery nest(){
  LinkedHashSet<Aggregation> innerAggregations=new LinkedHashSet<>();
  LinkedHashSet<Aggregation> outerAggregations=new LinkedHashSet<>();
  for (  Aggregation agg : aggregations) {
    Pair<Aggregation,Aggregation> split=agg.nest();
    innerAggregations.add(split.getRight());
    outerAggregations.add(split.getLeft());
  }
  TemplateDruidQuery innerQuery;
  if (isNested()) {
    innerQuery=new TemplateDruidQuery(innerAggregations,Collections.emptySet(),nestedQuery,null);
  }
 else {
    innerQuery=new TemplateDruidQuery(innerAggregations,Collections.emptySet(),null,null);
  }
  return new TemplateDruidQuery(outerAggregations,postAggregations,innerQuery,timeGrain);
}

public TemplateDruidQuery nest ( ) { LinkedHashSet < Aggregation > innerAggregations = new LinkedHashSet < > ( ) ; LinkedHashSet < Aggregation > outerAggregations = new LinkedHashSet < > ( ) ; for ( Aggregation agg : aggregations ) { Pair < Aggregation , Aggregation > split = agg . nest ( ) ; innerAggregations . add ( split . getRight ( ) ) ; outerAggregations . add ( split . getLeft ( ) ) ; } TemplateDruidQuery innerQuery ; if ( isNested ( ) ) { innerQuery = new TemplateDruidQuery ( innerAggregations , Collections . emptySet ( ) , nestedQuery , null ) ; } else { innerQuery = new TemplateDruidQuery ( innerAggregations , Collections . emptySet ( ) , null , null ) ; } return new TemplateDruidQuery ( outerAggregations , postAggregations , innerQuery , timeGrain ) ; }
transforms a n - pass query into a ( n + 1 ) - pass query . the original query is not mutated .
