aggregation

package
v2.0.3+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggFuncToPBExpr

func AggFuncToPBExpr(sc *stmtctx.StatementContext, client kv.Client, aggFunc *AggFuncDesc) *tipb.Expr

AggFuncToPBExpr converts aggregate function to pb.

func ExplainAggFunc

func ExplainAggFunc(agg *AggFuncDesc) string

ExplainAggFunc generates explain information for a aggregation function.

Types

type AggEvaluateContext

type AggEvaluateContext struct {
	DistinctChecker *distinctChecker
	Count           int64
	Value           types.Datum
	Buffer          *bytes.Buffer // Buffer is used for group_concat.
	GotFirstRow     bool          // It will check if the agg has met the first row key.
}

AggEvaluateContext is used to store intermediate result when calculating aggregate functions.

type AggFuncDesc

type AggFuncDesc struct {
	// Name represents the aggregation function name.
	Name string
	// Args represents the arguments of the aggregation function.
	Args []expression.Expression
	// RetTp represents the return type of the aggregation function.
	RetTp *types.FieldType
	// Mode represents the execution mode of the aggregation function.
	Mode AggFunctionMode
	// HasDistinct represents whether the aggregation function contains distinct attribute.
	HasDistinct bool
}

AggFuncDesc describes an aggregation function signature, only used in planner.

func NewAggFuncDesc

func NewAggFuncDesc(ctx sessionctx.Context, name string, args []expression.Expression, hasDistinct bool) *AggFuncDesc

NewAggFuncDesc creates an aggregation function signature descriptor.

func (*AggFuncDesc) CalculateDefaultValue

func (a *AggFuncDesc) CalculateDefaultValue(ctx sessionctx.Context, schema *expression.Schema) (types.Datum, bool)

CalculateDefaultValue gets the default value when the aggregation function's input is null. The input stands for the schema of Aggregation's child. If the function can't produce a default value, the second return value will be false.

func (*AggFuncDesc) Clone

func (a *AggFuncDesc) Clone() *AggFuncDesc

Clone copies an aggregation function signature totally.

func (*AggFuncDesc) Equal

func (a *AggFuncDesc) Equal(ctx sessionctx.Context, other *AggFuncDesc) bool

Equal checks whether two aggregation function signatures are equal.

func (*AggFuncDesc) GetAggFunc

func (a *AggFuncDesc) GetAggFunc() Aggregation

GetAggFunc gets an evaluator according to the aggregation function signature.

func (*AggFuncDesc) String

func (a *AggFuncDesc) String() string

String implements the fmt.Stringer interface.

type AggFunctionMode

type AggFunctionMode int

AggFunctionMode stands for the aggregation function's mode.

const (
	// CompleteMode function accepts origin data.
	CompleteMode AggFunctionMode = iota
	// FinalMode function accepts partial data.
	FinalMode
)

type Aggregation

type Aggregation interface {
	// Update during executing.
	Update(evalCtx *AggEvaluateContext, sc *stmtctx.StatementContext, row types.Row) error

	// GetPartialResult will called by coprocessor to get partial results. For avg function, partial results will return
	// sum and count values at the same time.
	GetPartialResult(evalCtx *AggEvaluateContext) []types.Datum

	// GetResult will be called when all data have been processed.
	GetResult(evalCtx *AggEvaluateContext) types.Datum

	// Create a new AggEvaluateContext for the aggregation function.
	CreateContext(sc *stmtctx.StatementContext) *AggEvaluateContext

	// Reset the content of the evaluate context.
	ResetContext(sc *stmtctx.StatementContext, evalCtx *AggEvaluateContext)
}

Aggregation stands for aggregate functions.

func NewDistAggFunc

func NewDistAggFunc(expr *tipb.Expr, fieldTps []*types.FieldType, sc *stmtctx.StatementContext) (Aggregation, error)

NewDistAggFunc creates new Aggregate function for mock tikv.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL