@ Nullable public GroupByQuery toGroupByQuery ( ) { if ( grouping == null ) { return null ; } final Filtration filtration = Filtration . create ( filter ) . optimize ( sourceQuerySignature ) ; final DimFilterHavingSpec havingSpec ; if ( grouping . getHavingFilter ( ) != null ) { havingSpec = new DimFilterHavingSpec ( Filtration . create ( grouping . getHavingFilter ( ) ) . optimizeFilterOnly ( sourceQuerySignature ) . getDimFilter ( ) , true ) ; } else { havingSpec = null ; } final List < PostAggregator > postAggregators = new ArrayList <> ( grouping . getPostAggregators ( ) ) ; if ( sortProject != null ) { postAggregators . addAll ( sortProject . getPostAggregators ( ) ) ; } return new GroupByQuery ( dataSource , filtration . getQuerySegmentSpec ( ) , getVirtualColumns ( true ) , filtration . getDimFilter ( ) , Granularities . ALL , grouping . getDimensionSpecs ( ) , grouping . getAggregatorFactories ( ) , postAggregators , havingSpec , limitSpec , null , ImmutableSortedMap . copyOf ( plannerContext . getQueryContext ( ) ) ) ; }
Return this query as a GroupBy query or null if this query is not compatible with GroupBy .