Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: enable revive for part #46086

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@
"types/json_binary_functions.go": "types/json_binary_functions.go",
"types/json_binary_test.go": "types/json_binary_test.go",
"ddl/": "ddl",
"expression/a": "expression/a code",
"expression/builtin.go": "expression/builtin code",
"expression/builtin_cast.go": "expression/builtin_cast code",
"server/": "server/ code",
Expand Down
4 changes: 2 additions & 2 deletions expression/aggregation/agg_to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ func AggFuncToPBExpr(sctx sessionctx.Context, client kv.Client, aggFunc *AggFunc
orderBy = append(orderBy, pbArg)
}
// encode GroupConcatMaxLen
GCMaxLen, err := sctx.GetSessionVars().GetSessionOrGlobalSystemVar(context.Background(), variable.GroupConcatMaxLen)
gcMaxLen, err := sctx.GetSessionVars().GetSessionOrGlobalSystemVar(context.Background(), variable.GroupConcatMaxLen)
if err != nil {
return nil, errors.Errorf("Error happened when buildGroupConcat: no system variable named '%s'", variable.GroupConcatMaxLen)
}
maxLen, err := strconv.ParseUint(GCMaxLen, 10, 64)
maxLen, err := strconv.ParseUint(gcMaxLen, 10, 64)
// Should never happen
if err != nil {
return nil, errors.Errorf("Error happened when buildGroupConcat: %s", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion expression/aggregation/avg.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ func (af *avgFunction) GetResult(evalCtx *AggEvaluateContext) (d types.Datum) {
}

// GetPartialResult implements Aggregation interface.
func (af *avgFunction) GetPartialResult(evalCtx *AggEvaluateContext) []types.Datum {
func (*avgFunction) GetPartialResult(evalCtx *AggEvaluateContext) []types.Datum {
return []types.Datum{types.NewIntDatum(evalCtx.Count), evalCtx.Value}
}
10 changes: 5 additions & 5 deletions expression/aggregation/base_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (a *baseFuncDesc) TypeInfer(ctx sessionctx.Context) error {
return nil
}

func (a *baseFuncDesc) typeInfer4Count(ctx sessionctx.Context) {
func (a *baseFuncDesc) typeInfer4Count(sessionctx.Context) {
a.RetTp = types.NewFieldType(mysql.TypeLonglong)
a.RetTp.SetFlen(21)
a.RetTp.SetDecimal(0)
Expand Down Expand Up @@ -182,7 +182,7 @@ func (a *baseFuncDesc) typeInfer4ApproxPercentile(ctx sessionctx.Context) error

// typeInfer4Sum should return a "decimal", otherwise it returns a "double".
// Because child returns integer or decimal type.
func (a *baseFuncDesc) typeInfer4Sum(ctx sessionctx.Context) {
func (a *baseFuncDesc) typeInfer4Sum(sessionctx.Context) {
switch a.Args[0].GetType().GetType() {
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong, mysql.TypeYear:
a.RetTp = types.NewFieldType(mysql.TypeNewDecimal)
Expand Down Expand Up @@ -216,7 +216,7 @@ func (a *baseFuncDesc) TypeInfer4AvgSum(avgRetType *types.FieldType) {

// typeInfer4Avg should returns a "decimal", otherwise it returns a "double".
// Because child returns integer or decimal type.
func (a *baseFuncDesc) typeInfer4Avg(ctx sessionctx.Context) {
func (a *baseFuncDesc) typeInfer4Avg(sessionctx.Context) {
switch a.Args[0].GetType().GetType() {
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong:
a.RetTp = types.NewFieldType(mysql.TypeNewDecimal)
Expand Down Expand Up @@ -291,7 +291,7 @@ func (a *baseFuncDesc) typeInfer4BitFuncs(ctx sessionctx.Context) {
a.Args[0] = expression.WrapWithCastAsInt(ctx, a.Args[0])
}

func (a *baseFuncDesc) typeInfer4JsonArrayAgg(ctx sessionctx.Context) {
func (a *baseFuncDesc) typeInfer4JsonArrayAgg(sessionctx.Context) {
a.RetTp = types.NewFieldType(mysql.TypeJSON)
types.SetBinChsClnFlag(a.RetTp)
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func (a *baseFuncDesc) typeInfer4LeadLag(ctx sessionctx.Context) {
}
}

func (a *baseFuncDesc) typeInfer4PopOrSamp(ctx sessionctx.Context) {
func (a *baseFuncDesc) typeInfer4PopOrSamp(sessionctx.Context) {
// var_pop/std/var_samp/stddev_samp's return value type is double
a.RetTp = types.NewFieldType(mysql.TypeDouble)
a.RetTp.SetFlen(mysql.MaxRealWidth)
Expand Down
4 changes: 2 additions & 2 deletions expression/aggregation/bit_and.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (bf *bitAndFunction) CreateContext(sc *stmtctx.StatementContext) *AggEvalua
return evalCtx
}

func (bf bitAndFunction) ResetContext(sc *stmtctx.StatementContext, evalCtx *AggEvaluateContext) {
func (*bitAndFunction) ResetContext(_ *stmtctx.StatementContext, evalCtx *AggEvaluateContext) {
evalCtx.Value.SetUint64(math.MaxUint64)
}

Expand All @@ -58,7 +58,7 @@ func (bf *bitAndFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Statem
}

// GetResult implements Aggregation interface.
func (bf *bitAndFunction) GetResult(evalCtx *AggEvaluateContext) types.Datum {
func (*bitAndFunction) GetResult(evalCtx *AggEvaluateContext) types.Datum {
return evalCtx.Value
}

Expand Down
4 changes: 2 additions & 2 deletions expression/aggregation/bit_or.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (bf *bitOrFunction) CreateContext(sc *stmtctx.StatementContext) *AggEvaluat
return evalCtx
}

func (bf *bitOrFunction) ResetContext(sc *stmtctx.StatementContext, evalCtx *AggEvaluateContext) {
func (*bitOrFunction) ResetContext(_ *stmtctx.StatementContext, evalCtx *AggEvaluateContext) {
evalCtx.Value.SetUint64(0)
}

Expand All @@ -56,7 +56,7 @@ func (bf *bitOrFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Stateme
}

// GetResult implements Aggregation interface.
func (bf *bitOrFunction) GetResult(evalCtx *AggEvaluateContext) types.Datum {
func (*bitOrFunction) GetResult(evalCtx *AggEvaluateContext) types.Datum {
return evalCtx.Value
}

Expand Down
4 changes: 2 additions & 2 deletions expression/aggregation/bit_xor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (bf *bitXorFunction) CreateContext(sc *stmtctx.StatementContext) *AggEvalua
return evalCtx
}

func (bf *bitXorFunction) ResetContext(sc *stmtctx.StatementContext, evalCtx *AggEvaluateContext) {
func (*bitXorFunction) ResetContext(_ *stmtctx.StatementContext, evalCtx *AggEvaluateContext) {
evalCtx.Value.SetUint64(0)
}

Expand All @@ -56,7 +56,7 @@ func (bf *bitXorFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Statem
}

// GetResult implements Aggregation interface.
func (bf *bitXorFunction) GetResult(evalCtx *AggEvaluateContext) types.Datum {
func (*bitXorFunction) GetResult(evalCtx *AggEvaluateContext) types.Datum {
return evalCtx.Value
}

Expand Down
4 changes: 2 additions & 2 deletions expression/aggregation/concat.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ type concatFunction struct {
truncated bool
}

func (cf *concatFunction) writeValue(evalCtx *AggEvaluateContext, val types.Datum) {
func (*concatFunction) writeValue(evalCtx *AggEvaluateContext, val types.Datum) {
if val.Kind() == types.KindBytes {
evalCtx.Buffer.Write(val.GetBytes())
} else {
fmt.Fprintf(evalCtx.Buffer, "%v", val.GetValue())
}
}

func (cf *concatFunction) initSeparator(sc *stmtctx.StatementContext, row chunk.Row) error {
func (cf *concatFunction) initSeparator(_ *stmtctx.StatementContext, row chunk.Row) error {
sepArg := cf.Args[len(cf.Args)-1]
sepDatum, err := sepArg.Eval(row)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions expression/aggregation/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type countFunction struct {
}

// Update implements Aggregation interface.
func (cf *countFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.StatementContext, row chunk.Row) error {
func (cf *countFunction) Update(evalCtx *AggEvaluateContext, _ *stmtctx.StatementContext, row chunk.Row) error {
var datumBuf []types.Datum
if cf.HasDistinct {
datumBuf = make([]types.Datum, 0, len(cf.Args))
Expand Down Expand Up @@ -68,7 +68,7 @@ func (cf *countFunction) ResetContext(sc *stmtctx.StatementContext, evalCtx *Agg
}

// GetResult implements Aggregation interface.
func (cf *countFunction) GetResult(evalCtx *AggEvaluateContext) (d types.Datum) {
func (*countFunction) GetResult(evalCtx *AggEvaluateContext) (d types.Datum) {
d.SetInt64(evalCtx.Count)
return d
}
Expand Down
8 changes: 4 additions & 4 deletions expression/aggregation/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func NewAggFuncDesc(ctx sessionctx.Context, name string, args []expression.Expre
}

// NewAggFuncDescForWindowFunc creates an aggregation function from window functions, where baseFuncDesc may be ready.
func NewAggFuncDescForWindowFunc(ctx sessionctx.Context, Desc *WindowFuncDesc, hasDistinct bool) (*AggFuncDesc, error) {
if Desc.RetTp == nil { // safety check
return NewAggFuncDesc(ctx, Desc.Name, Desc.Args, hasDistinct)
func NewAggFuncDescForWindowFunc(ctx sessionctx.Context, desc *WindowFuncDesc, hasDistinct bool) (*AggFuncDesc, error) {
if desc.RetTp == nil { // safety check
return NewAggFuncDesc(ctx, desc.Name, desc.Args, hasDistinct)
}
return &AggFuncDesc{baseFuncDesc: baseFuncDesc{Desc.Name, Desc.Args, Desc.RetTp}, HasDistinct: hasDistinct}, nil
return &AggFuncDesc{baseFuncDesc: baseFuncDesc{desc.Name, desc.Args, desc.RetTp}, HasDistinct: hasDistinct}, nil
}

// String implements the fmt.Stringer interface.
Expand Down
6 changes: 3 additions & 3 deletions expression/aggregation/first_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type firstRowFunction struct {
}

// Update implements Aggregation interface.
func (ff *firstRowFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.StatementContext, row chunk.Row) error {
func (ff *firstRowFunction) Update(evalCtx *AggEvaluateContext, _ *stmtctx.StatementContext, row chunk.Row) error {
if evalCtx.GotFirstRow {
return nil
}
Expand All @@ -43,11 +43,11 @@ func (ff *firstRowFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Stat
}

// GetResult implements Aggregation interface.
func (ff *firstRowFunction) GetResult(evalCtx *AggEvaluateContext) types.Datum {
func (*firstRowFunction) GetResult(evalCtx *AggEvaluateContext) types.Datum {
return evalCtx.Value
}

func (ff *firstRowFunction) ResetContext(_ *stmtctx.StatementContext, evalCtx *AggEvaluateContext) {
func (*firstRowFunction) ResetContext(_ *stmtctx.StatementContext, evalCtx *AggEvaluateContext) {
evalCtx.GotFirstRow = false
}

Expand Down
2 changes: 1 addition & 1 deletion expression/aggregation/max_min.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type maxMinFunction struct {
}

// GetResult implements Aggregation interface.
func (mmf *maxMinFunction) GetResult(evalCtx *AggEvaluateContext) (d types.Datum) {
func (*maxMinFunction) GetResult(evalCtx *AggEvaluateContext) (d types.Datum) {
return evalCtx.Value
}

Expand Down
2 changes: 1 addition & 1 deletion expression/aggregation/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (sf *sumFunction) Update(evalCtx *AggEvaluateContext, sc *stmtctx.Statement
}

// GetResult implements Aggregation interface.
func (sf *sumFunction) GetResult(evalCtx *AggEvaluateContext) (d types.Datum) {
func (*sumFunction) GetResult(evalCtx *AggEvaluateContext) (d types.Datum) {
return evalCtx.Value
}

Expand Down