func flattenAggregationExpressions(ctx *sql.Context, a *Analyzer, n sql.Node, scope *Scope) (sql.Node, error) {
	span, _ := ctx.Span("flatten_aggregation_exprs")
	defer span.Finish()
	if !n.Resolved() {
		return n, nil
	}
	return plan.TransformUp(n, func(n sql.Node) (sql.Node, error) {
		switch n := n.(type) {
		case *plan.Window:
			if !hasHiddenAggregations(n.SelectExprs) && !hasHiddenWindows(n.SelectExprs) {
				return n, nil
			}
			return flattenedWindow(ctx, n.SelectExprs, n.Child)
		case *plan.GroupBy:
			if !hasHiddenAggregations(n.SelectedExprs) {
				return n, nil
			}
			return flattenedGroupBy(ctx, n.SelectedExprs, n.GroupByExprs, n.Child)
		default:
			return n, nil
		}
	})
}
flattenAggregationExpressions flattens any complex aggregate or window expressions in a GroupBy or Window node and
adds a projection on top of the result. The child terms of any complex expressions get pushed down to become selected
expressions in the GroupBy or Window, and then a new project node re-applies the original expression to the new
schema of the flattened node.
e.g. GroupBy(sum(a) + sum(b)) becomes project(sum(a) + sum(b), GroupBy(sum(a), sum(b)).
e.g. Window(sum(a) + sum(b) over (partition by a)) becomes
project(sum(a) + sum(b) over (partition by a), Window(sum(a), sum(b) over (partition by a))).
package analyzer
import (
	"github.com/dolthub/go-mysql-server/sql"
	"github.com/dolthub/go-mysql-server/sql/expression"
	"github.com/dolthub/go-mysql-server/sql/plan"
)