fe/src/main/java/com/cloudera/impala/analysis/AggregateInfo.java
/**
   * Mark slots required for this aggregation as materialized:
   * - all grouping output slots as well as grouping exprs
   * - for non-distinct aggregation: the aggregate exprs of materialized aggregate slots;
   *   this assumes that the output slots corresponding to aggregate exprs have already
   *   been marked by the consumer of this select block
   * - for distinct aggregation, we mark all aggregate output slots in order to keep
   *   things simple
   * Also computes materializedAggregateExprs.
   * This call must be idempotent because it may be called more than once for Union stmt.
   */
Mark slots required for this aggregation as materialized:
- all grouping output slots as well as grouping exprs
- for non-distinct aggregation: the aggregate exprs of materialized aggregate slots;
this assumes that the output slots corresponding to aggregate exprs have already
been marked by the consumer of this select block
- for distinct aggregation, we mark all aggregate output slots in order to keep
things simple
Also computes materializedAggregateExprs.
This call must be idempotent because it may be called more than once for Union stmt.
Mark slots required for this aggregation as materialized : - all grouping output slots as well as grouping exprs - for non - distinct aggregation : the aggregate exprs of materialized aggregate slots ; this assumes that the output slots corresponding to aggregate exprs have already been marked by the consumer of this select block - for distinct aggregation we mark all aggregate output slots in order to keep things simple Also computes materializedAggregateExprs . This call must be idempotent because it may be called more than once for Union stmt .
public void materializeRequiredSlots(Analyzer analyzer, Expr.SubstitutionMap smap) {
    for (int i = 0; i < groupingExprs_.size(); ++i) {
      aggTupleDesc_.getSlots().get(i).setIsMaterialized(true);
    }
    materializedAggregateSlots_.clear();
    List<Expr> exprs = Lists.newArrayList();
    exprs.addAll(groupingExprs_);
    for (int i = 0; i < aggregateExprs_.size(); ++i) {
      SlotDescriptor slotDesc = aggTupleDesc_.getSlots().get(groupingExprs_.size() + i);
      if (isDistinctAgg_) slotDesc.setIsMaterialized(true);
      if (!slotDesc.isMaterialized()) continue;
      exprs.add(aggregateExprs_.get(i));
      materializedAggregateSlots_.add(i);
    }
    List<Expr> resolvedExprs = Expr.cloneList(exprs, smap);
    analyzer.materializeSlots(resolvedExprs);
    if (isDistinctAgg_) {
      secondPhaseDistinctAggInfo_.materializeRequiredSlots(analyzer, null);
    }
  }
public void materializeRequiredSlots ( Analyzer analyzer , Expr . SubstitutionMap smap ) { for ( int i = 0 ; i < groupingExprs_ . size ( ) ; ++ i ) { aggTupleDesc_ . getSlots ( ) . get ( i ) . setIsMaterialized ( true ) ; } materializedAggregateSlots_ . clear ( ) ; List < Expr > exprs = Lists . newArrayList ( ) ; exprs . addAll ( groupingExprs_ ) ; for ( int i = 0 ; i < aggregateExprs_ . size ( ) ; ++ i ) { SlotDescriptor slotDesc = aggTupleDesc_ . getSlots ( ) . get ( groupingExprs_ . size ( ) + i ) ; if ( isDistinctAgg_ ) slotDesc . setIsMaterialized ( true ) ; if ( ! slotDesc . isMaterialized ( ) ) continue ; exprs . add ( aggregateExprs_ . get ( i ) ) ; materializedAggregateSlots_ . add ( i ) ; } List < Expr > resolvedExprs = Expr . cloneList ( exprs , smap ) ; analyzer . materializeSlots ( resolvedExprs ) ; if ( isDistinctAgg_ ) { secondPhaseDistinctAggInfo_ . materializeRequiredSlots ( analyzer , null ) ; } }
Mark slots required for this aggregation as materialized:
 - all grouping output slots as well as grouping exprs
 - for non-distinct aggregation: the aggregate exprs of materialized aggregate slots;
   this assumes that the output slots corresponding to aggregate exprs have already
   been marked by the consumer of this select block
 - for distinct aggregation, we mark all aggregate output slots in order to keep
   things simple
 Also computes materializedAggregateExprs.
Mark slots required for this aggregation as materialized : - all grouping output slots as well as grouping exprs - for non - distinct aggregation : the aggregate exprs of materialized aggregate slots ; this assumes that the output slots corresponding to aggregate exprs have already been marked by the consumer of this select block - for distinct aggregation we mark all aggregate output slots in order to keep things simple Also computes materializedAggregateExprs .
// collect input exprs: grouping exprs plus aggregate exprs that need to be // materialized