func (e *Evaluator) evalAggAvg(v *ast.AggregateFuncExpr) { ctx := v.GetContext() switch x := ctx.Value.(type) { case float64: t := x / float64(ctx.Count) ctx.Value = t v.SetFloat64(t) case mysql.Decimal: t := x.Div(mysql.NewDecimalFromUint(uint64(ctx.Count), 0)) ctx.Value = t v.SetMysqlDecimal(t) } }
func (e *Evaluator) evalAggAvg(v *ast.AggregateFuncExpr) { ctx := v.GetContext() switch ctx.Value.Kind() { case types.KindFloat64: t := ctx.Value.GetFloat64() / float64(ctx.Count) v.SetValue(t) case types.KindMysqlDecimal: x := ctx.Value.GetMysqlDecimal() t := x.Div(mysql.NewDecimalFromUint(uint64(ctx.Count), 0)) v.SetMysqlDecimal(t) } ctx.Value = *v.GetDatum() }
func (e *Evaluator) evalAggAvg(v *ast.AggregateFuncExpr) { ctx := v.GetContext() switch ctx.Value.Kind() { case types.KindFloat64: t := ctx.Value.GetFloat64() / float64(ctx.Count) v.SetValue(t) case types.KindMysqlDecimal: x := ctx.Value.GetMysqlDecimal() var y, to mysql.MyDecimal y.FromUint(uint64(ctx.Count)) mysql.DecimalDiv(x, &y, &to, mysql.DivFracIncr) to.Round(&to, ctx.Value.Frac()+mysql.DivFracIncr) v.SetMysqlDecimal(&to) } ctx.Value = *v.GetDatum() }