func (a *avgBuffer) Dispose() {
	expression.Dispose(a.expr)
}
Dispose implements the Disposable interface.
package aggregation
import (
	"fmt"
	"github.com/dolthub/go-mysql-server/sql"
	"github.com/dolthub/go-mysql-server/sql/expression"
)
type Avg struct {
	expression.UnaryExpression
}
var _ sql.FunctionExpression = (*Avg)(nil)
var _ sql.Aggregation = (*Avg)(nil)
func NewAvg(e sql.Expression) *Avg {
	return &Avg{expression.UnaryExpression{Child: e}}
}
func (a *Avg) FunctionName() string {
	return "avg"
}
func (a *Avg) String() string {
	return fmt.Sprintf("AVG(%s)", a.Child)
}
func (a *Avg) Type() sql.Type {
	return sql.Float64
}
func (a *Avg) IsNullable() bool {
	return true
}
func (a *Avg) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
	return nil, ErrEvalUnsupportedOnAggregation.New("Avg")
}
func (a *Avg) WithChildren(children ...sql.Expression) (sql.Expression, error) {
	if len(children) != 1 {
		return nil, sql.ErrInvalidChildrenNumber.New(a, len(children), 1)
	}
	return NewAvg(children[0]), nil
}
func (a *Avg) NewBuffer() (sql.AggregationBuffer, error) {
	const (
		sum  = float64(0)
		rows = int64(0)
	)
	bufferChild, err := expression.Clone(a.UnaryExpression.Child)
	if err != nil {
		return nil, err
	}
	return &avgBuffer{sum, rows, bufferChild}, nil
}
type avgBuffer struct {
	sum  float64
	rows int64
	expr sql.Expression
}
func (a *avgBuffer) Update(ctx *sql.Context, row sql.Row) error {
	v, err := a.expr.Eval(ctx, row)
	if err != nil {
		return err
	}
	if v == nil {
		return nil
	}
	v, err = sql.Float64.Convert(v)
	if err != nil {
		v = float64(0)
	}
	a.sum += v.(float64)
	a.rows += 1
	return nil
}
func (a *avgBuffer) Eval(ctx *sql.Context) (interface{}, error) {
	if a.sum == 0 && a.rows == 0 {
		return nil, nil
	}
	if a.rows == 0 {
		return float64(0), nil
	}
	return a.sum / float64(a.rows), nil
}