code: func buildAvg(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
  	base := baseAggFunc{
  		args:    aggFuncDesc.Args,
  		ordinal: ordinal,
  	}
  	switch aggFuncDesc.Mode {
  	// Build avg functions which consume the original data and remove the
  	// duplicated input of the same group.
  	case aggregation.DedupMode:
  		return nil // not implemented yet.
  
  	// Build avg functions which consume the original data and update their
  	// partial results.
  	case aggregation.CompleteMode, aggregation.Partial1Mode:
  		switch aggFuncDesc.RetTp.EvalType() {
  		case types.ETDecimal:
  			if aggFuncDesc.HasDistinct {
  				return &avgOriginal4DistinctDecimal{base}
  			}
  			return &avgOriginal4Decimal{baseAvgDecimal{base}}
  		default:
  			if aggFuncDesc.HasDistinct {
  				return &avgOriginal4DistinctFloat64{base}
  			}
  			return &avgOriginal4Float64{baseAvgFloat64{base}}
  		}
  
  	// Build avg functions which consume the partial result of other avg
  	// functions and update their partial results.
  	case aggregation.Partial2Mode, aggregation.FinalMode:
  		switch aggFuncDesc.RetTp.Tp {
  		case mysql.TypeNewDecimal:
  			return &avgPartial4Decimal{baseAvgDecimal{base}}
  		case mysql.TypeDouble:
  			return &avgPartial4Float64{baseAvgFloat64{base}}
  		}
  	}
  	return nil
  }
docs: // buildAvg builds the AggFunc implementation for function "AVG".