tidb: github.com/pingcap/tidb/expression/aggregation Index | Files

package aggregation

import "github.com/pingcap/tidb/expression/aggregation"

Index

Package Files

agg_to_pb.go aggregation.go avg.go base_func.go bit_and.go bit_or.go bit_xor.go concat.go count.go descriptor.go explain.go first_row.go max_min.go sum.go util.go window_func.go

func AggFuncToPBExpr Uses

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

AggFuncToPBExpr converts aggregate function to pb.

func ExplainAggFunc Uses

func ExplainAggFunc(agg *AggFuncDesc) string

ExplainAggFunc generates explain information for a aggregation function.

func IsAllFirstRow Uses

func IsAllFirstRow(aggFuncs []*AggFuncDesc) bool

IsAllFirstRow checks whether functions in `aggFuncs` are all FirstRow.

func NeedCount Uses

func NeedCount(name string) bool

NeedCount indicates whether the aggregate function should record count.

func NeedFrame Uses

func NeedFrame(name string) bool

NeedFrame checks if the function need frame specification.

func NeedValue Uses

func NeedValue(name string) bool

NeedValue indicates whether the aggregate function should record value.

type AggEvaluateContext Uses

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 Uses

type AggFuncDesc struct {

    // Mode represents the execution mode of the aggregation function.
    Mode AggFunctionMode
    // HasDistinct represents whether the aggregation function contains distinct attribute.
    HasDistinct bool
    // contains filtered or unexported fields
}

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

func NewAggFuncDesc Uses

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

NewAggFuncDesc creates an aggregation function signature descriptor.

func (*AggFuncDesc) Clone Uses

func (a *AggFuncDesc) Clone() *AggFuncDesc

Clone copies an aggregation function signature totally.

func (*AggFuncDesc) Equal Uses

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

Equal checks whether two aggregation function signatures are equal.

func (*AggFuncDesc) EvalNullValueInOuterJoin Uses

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

EvalNullValueInOuterJoin gets the null value when the aggregation is upon an outer join, and the aggregation function's input is null. If there is no matching row for the inner table of an outer join, an aggregation function only involves constant and/or columns belongs to the inner table will be set to the null value. The input stands for the schema of Aggregation's child. If the function can't produce a null value, the second return value will be false. e.g. Table t with only one row: +-------+---------+---------+ | Table | Field | Type | +-------+---------+---------+ | t | a | int(11) | +-------+---------+---------+ +------+ | a | +------+ | 1 | +------+

Table s which is empty: +-------+---------+---------+ | Table | Field | Type | +-------+---------+---------+ | s | a | int(11) | +-------+---------+---------+

Query: `select t.a as `t.a`, count(95), sum(95), avg(95), bit_or(95), bit_and(95), bit_or(95), max(95), min(95), s.a as `s.a`, avg(95) from t left join s on t.a = s.a;` +------+-----------+---------+---------+------------+-------------+------------+---------+---------+------+----------+ | t.a | count(95) | sum(95) | avg(95) | bit_or(95) | bit_and(95) | bit_or(95) | max(95) | min(95) | s.a | avg(s.a) | +------+-----------+---------+---------+------------+-------------+------------+---------+---------+------+----------+ | 1 | 1 | 95 | 95.0000 | 95 | 95 | 95 | 95 | 95 | NULL | NULL | +------+-----------+---------+---------+------------+-------------+------------+---------+---------+------+----------+

func (*AggFuncDesc) GetAggFunc Uses

func (a *AggFuncDesc) GetAggFunc(ctx sessionctx.Context) Aggregation

GetAggFunc gets an evaluator according to the aggregation function signature.

func (*AggFuncDesc) GetDefaultValue Uses

func (a *AggFuncDesc) GetDefaultValue() (v types.Datum)

GetDefaultValue gets the default value when the function's input is null. According to MySQL, default values of the function are listed as follows: e.g. Table t which is empty: +-------+---------+---------+ | Table | Field | Type | +-------+---------+---------+ | t | a | int(11) | +-------+---------+---------+

Query: `select a, avg(a), sum(a), count(a), bit_xor(a), bit_or(a), bit_and(a), max(a), min(a), group_concat(a) from t;` +------+--------+--------+----------+------------+-----------+----------------------+--------+--------+-----------------+ | a | avg(a) | sum(a) | count(a) | bit_xor(a) | bit_or(a) | bit_and(a) | max(a) | min(a) | group_concat(a) | +------+--------+--------+----------+------------+-----------+----------------------+--------+--------+-----------------+ | NULL | NULL | NULL | 0 | 0 | 0 | 18446744073709551615 | NULL | NULL | NULL | +------+--------+--------+----------+------------+-----------+----------------------+--------+--------+-----------------+

func (*AggFuncDesc) Split Uses

func (a *AggFuncDesc) Split(ordinal []int) (partialAggDesc, finalAggDesc *AggFuncDesc)

Split splits `a` into two aggregate descriptors for partial phase and final phase individually. This function is only used when executing aggregate function parallelly. ordinal indicates the column ordinal of the intermediate result.

func (*AggFuncDesc) String Uses

func (a *AggFuncDesc) String() string

String implements the fmt.Stringer interface.

func (*AggFuncDesc) WrapCastForAggArgs Uses

func (a *AggFuncDesc) WrapCastForAggArgs(ctx sessionctx.Context)

WrapCastForAggArgs wraps the args of an aggregate function with a cast function.

type AggFunctionMode Uses

type AggFunctionMode int

AggFunctionMode stands for the aggregation function's mode.

const (
    CompleteMode AggFunctionMode = iota
    FinalMode
    Partial1Mode
    Partial2Mode
    DedupMode
)

|-----------------|--------------|--------------| | AggFunctionMode | input | output | |-----------------|--------------|--------------| | CompleteMode | origin data | final result | | FinalMode | partial data | final result | | Partial1Mode | origin data | partial data | | Partial2Mode | partial data | partial data | | DedupMode | origin data | origin data | |-----------------|--------------|--------------|

type Aggregation Uses

type Aggregation interface {
    // Update during executing.
    Update(evalCtx *AggEvaluateContext, sc *stmtctx.StatementContext, row chunk.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

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

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

Aggregation stands for aggregate functions.

func NewDistAggFunc Uses

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

NewDistAggFunc creates new Aggregate function for mock tikv.

type WindowFuncDesc Uses

type WindowFuncDesc struct {
    // contains filtered or unexported fields
}

WindowFuncDesc describes a window function signature, only used in planner.

func NewWindowFuncDesc Uses

func NewWindowFuncDesc(ctx sessionctx.Context, name string, args []expression.Expression) (*WindowFuncDesc, error)

NewWindowFuncDesc creates a window function signature descriptor.

func (*WindowFuncDesc) GetDefaultValue Uses

func (a *WindowFuncDesc) GetDefaultValue() (v types.Datum)

GetDefaultValue gets the default value when the function's input is null. According to MySQL, default values of the function are listed as follows: e.g. Table t which is empty: +-------+---------+---------+ | Table | Field | Type | +-------+---------+---------+ | t | a | int(11) | +-------+---------+---------+

Query: `select a, avg(a), sum(a), count(a), bit_xor(a), bit_or(a), bit_and(a), max(a), min(a), group_concat(a) from t;` +------+--------+--------+----------+------------+-----------+----------------------+--------+--------+-----------------+ | a | avg(a) | sum(a) | count(a) | bit_xor(a) | bit_or(a) | bit_and(a) | max(a) | min(a) | group_concat(a) | +------+--------+--------+----------+------------+-----------+----------------------+--------+--------+-----------------+ | NULL | NULL | NULL | 0 | 0 | 0 | 18446744073709551615 | NULL | NULL | NULL | +------+--------+--------+----------+------------+-----------+----------------------+--------+--------+-----------------+

func (*WindowFuncDesc) String Uses

func (a *WindowFuncDesc) String() string

String implements the fmt.Stringer interface.

func (*WindowFuncDesc) WrapCastForAggArgs Uses

func (a *WindowFuncDesc) WrapCastForAggArgs(ctx sessionctx.Context)

WrapCastForAggArgs wraps the args of an aggregate function with a cast function.

Package aggregation imports 22 packages (graph) and is imported by 35 packages. Updated 2019-08-20. Refresh now. Tools for package owners.