fe/src/main/java/com/cloudera/impala/analysis/AggregateInfo.java
/**
   * Create smap to map original grouping and aggregate exprs onto output
   * of secondPhaseDistinctAggInfo.
   */
Create smap to map original grouping and aggregate exprs onto output
of secondPhaseDistinctAggInfo.
Create smap to map original grouping and aggregate exprs onto output of secondPhaseDistinctAggInfo .
private void createSecondPhaseDistinctAggSMap(
      AggregateInfo inputAggInfo, ArrayList<FunctionCallExpr> distinctAggExprs) {
    aggTupleSMap_.clear();
    int slotIdx = 0;
    ArrayList<SlotDescriptor> slotDescs = aggTupleDesc_.getSlots();
    int numDistinctParams = distinctAggExprs.get(0).getChildren().size();
    int numOrigGroupingExprs =
        inputAggInfo.getGroupingExprs().size() - numDistinctParams;
    Preconditions.checkState(slotDescs.size() ==
        numOrigGroupingExprs + distinctAggExprs.size() +
        inputAggInfo.getAggregateExprs().size());
    for (int i = 0; i < numOrigGroupingExprs; ++i, ++slotIdx) {
      Expr groupingExpr = inputAggInfo.getGroupingExprs().get(i);
      aggTupleSMap_.addMapping(
          groupingExpr.clone(null), new SlotRef(slotDescs.get(slotIdx)));
    }
    for (int i = 0; i < distinctAggExprs.size(); ++i, ++slotIdx) {
      Expr aggExpr = distinctAggExprs.get(i);
      aggTupleSMap_.addMapping(
          aggExpr.clone(null), (new SlotRef(slotDescs.get(slotIdx))));
    }
    for (int i = 0; i < inputAggInfo.getAggregateExprs().size(); ++i, ++slotIdx) {
      Expr aggExpr = inputAggInfo.getAggregateExprs().get(i);
      aggTupleSMap_.addMapping(aggExpr.clone(null), new SlotRef(slotDescs.get(slotIdx)));
    }
  }
private void createSecondPhaseDistinctAggSMap ( AggregateInfo inputAggInfo , ArrayList < FunctionCallExpr > distinctAggExprs ) { aggTupleSMap_ . clear ( ) ; int slotIdx = 0 ; ArrayList < SlotDescriptor > slotDescs = aggTupleDesc_ . getSlots ( ) ; int numDistinctParams = distinctAggExprs . get ( 0 ) . getChildren ( ) . size ( ) ; int numOrigGroupingExprs = inputAggInfo . getGroupingExprs ( ) . size ( ) - numDistinctParams ; Preconditions . checkState ( slotDescs . size ( ) == numOrigGroupingExprs + distinctAggExprs . size ( ) + inputAggInfo . getAggregateExprs ( ) . size ( ) ) ; for ( int i = 0 ; i < numOrigGroupingExprs ; ++ i , ++ slotIdx ) { Expr groupingExpr = inputAggInfo . getGroupingExprs ( ) . get ( i ) ; aggTupleSMap_ . addMapping ( groupingExpr . clone ( null ) , new SlotRef ( slotDescs . get ( slotIdx ) ) ) ; } for ( int i = 0 ; i < distinctAggExprs . size ( ) ; ++ i , ++ slotIdx ) { Expr aggExpr = distinctAggExprs . get ( i ) ; aggTupleSMap_ . addMapping ( aggExpr . clone ( null ) , ( new SlotRef ( slotDescs . get ( slotIdx ) ) ) ) ; } for ( int i = 0 ; i < inputAggInfo . getAggregateExprs ( ) . size ( ) ; ++ i , ++ slotIdx ) { Expr aggExpr = inputAggInfo . getAggregateExprs ( ) . get ( i ) ; aggTupleSMap_ . addMapping ( aggExpr . clone ( null ) , new SlotRef ( slotDescs . get ( slotIdx ) ) ) ; } }
Create smap to map original grouping and aggregate exprs onto output
 of secondPhaseDistinctAggInfo.
Create smap to map original grouping and aggregate exprs onto output of secondPhaseDistinctAggInfo .
// original grouping exprs -> first m slots // distinct agg exprs -> next n slots // remaining agg exprs -> remaining slots