aggregation

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggFuncToPBExpr

func AggFuncToPBExpr(sc *variable.StatementContext, client kv.Client, aggFunc Aggregation) *tipb.Expr

AggFuncToPBExpr converts aggregate function to pb.

func ExplainAggFunc

func ExplainAggFunc(agg Aggregation) 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 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 {
	fmt.Stringer
	json.Marshaler

	// Update during executing.
	Update(ctx *AggEvaluateContext, sc *variable.StatementContext, row []types.Datum) 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(ctx *AggEvaluateContext) []types.Datum

	// SetMode sets aggFunctionMode for aggregate function.
	SetMode(mode AggFunctionMode)

	// GetMode gets aggFunctionMode from aggregate function.
	GetMode() AggFunctionMode

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

	// GetArgs stands for getting all arguments.
	GetArgs() []expression.Expression

	// GetName gets the aggregation function name.
	GetName() string

	// SetArgs sets argument by index.
	SetArgs(args []expression.Expression)

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

	// IsDistinct indicates if the aggregate function contains distinct attribute.
	IsDistinct() bool

	// Equal checks whether two aggregation functions are equal.
	Equal(agg Aggregation, ctx context.Context) bool

	// Clone copies an aggregate function totally.
	Clone() Aggregation

	// GetType gets field type of aggregate function.
	GetType() *types.FieldType

	// CalculateDefaultValue gets the default value when the aggregate 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.
	CalculateDefaultValue(schema *expression.Schema, ctx context.Context) (types.Datum, bool)
}

Aggregation stands for aggregate functions.

func NewAggFunction

func NewAggFunction(funcType string, funcArgs []expression.Expression, distinct bool) Aggregation

NewAggFunction creates a new Aggregation.

func NewDistAggFunc

func NewDistAggFunc(expr *tipb.Expr, fieldTps []*types.FieldType, sc *variable.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