func (h *rpcHandler) aggregate(ctx *selectContext, handle int64, row map[int64][]byte) error {
	// Put row data into evaluate context for later evaluation.
	err := h.setColumnValueToCtx(ctx, handle, row, ctx.aggColumns)
	if err != nil {
		return errors.Trace(err)
	}
	// Get group key.
	gk, err := h.getGroupKey(ctx)
	if err != nil {
		return errors.Trace(err)
	}
	if _, ok := ctx.groups[string(gk)]; !ok {
		ctx.groups[string(gk)] = true
		ctx.groupKeys = append(ctx.groupKeys, gk)
	}
	// Update aggregate funcs.
	for _, agg := range ctx.aggregates {
		agg.currentGroup = gk
		args := make([]types.Datum, 0, len(agg.expr.Children))
		// Evaluate arguments.
		for _, x := range agg.expr.Children {
			cv, err := ctx.eval.Eval(x)
			if err != nil {
				return errors.Trace(err)
			}
			args = append(args, cv)
		}
		agg.update(ctx, args)
	}
	return nil
}
// Update aggregate functions with rows.
Update aggregate functions with rows.
// Update aggregate functions with rows .
func (h *rpcHandler) aggregate(ctx *selectContext, handle int64, row map[int64][]byte) error {
	err := h.setColumnValueToCtx(ctx, handle, row, ctx.aggColumns)
	if err != nil {
		return errors.Trace(err)
	}
	gk, err := h.getGroupKey(ctx)
	if err != nil {
		return errors.Trace(err)
	}
	if _, ok := ctx.groups[string(gk)]; !ok {
		ctx.groups[string(gk)] = true
		ctx.groupKeys = append(ctx.groupKeys, gk)
	}
	for _, agg := range ctx.aggregates {
		agg.currentGroup = gk
		args := make([]types.Datum, 0, len(agg.expr.Children))
		for _, x := range agg.expr.Children {
			cv, err := ctx.eval.Eval(x)
			if err != nil {
				return errors.Trace(err)
			}
			args = append(args, cv)
		}
		agg.update(ctx, args)
	}
	return nil
}
func ( h * rpcHandler ) aggregate ( ctx * selectContext , handle int64 , row map [ int64 ] [ ] byte ) error { err := h . setColumnValueToCtx ( ctx , handle , row , ctx . aggColumns ) if err != nil { return errors . Trace ( err ) } gk , err := h . getGroupKey ( ctx ) if err != nil { return errors . Trace ( err ) } if _ , ok := ctx . groups [ string ( gk ) ] ; ! ok { ctx . groups [ string ( gk ) ] = true ctx . groupKeys = append ( ctx . groupKeys , gk ) } for _ , agg := range ctx . aggregates { agg . currentGroup = gk args := make ( [ ] types . Datum , 0 , len ( agg . expr . Children ) ) for _ , x := range agg . expr . Children { cv , err := ctx . eval . Eval ( x ) if err != nil { return errors . Trace ( err ) } args = append ( args , cv ) } agg . update ( ctx , args ) } return nil }
Update aggregate functions with rows.
Update aggregate functions with rows .
// Put row data into evaluate context for later evaluation. // Get group key. // Update aggregate funcs. // Evaluate arguments.