From 0455d930788de0de3c679073dfb361e9694c4d09 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 15 Aug 2023 12:38:00 +0800 Subject: [PATCH] expression: enable revive for part (#46086) ref pingcap/tidb#40786 --- build/nogo_config.json | 1 + expression/aggregation/agg_to_pb.go | 4 ++-- expression/aggregation/avg.go | 2 +- expression/aggregation/base_func.go | 10 +++++----- expression/aggregation/bit_and.go | 4 ++-- expression/aggregation/bit_or.go | 4 ++-- expression/aggregation/bit_xor.go | 4 ++-- expression/aggregation/concat.go | 4 ++-- expression/aggregation/count.go | 4 ++-- expression/aggregation/descriptor.go | 8 ++++---- expression/aggregation/first_row.go | 6 +++--- expression/aggregation/max_min.go | 2 +- expression/aggregation/sum.go | 2 +- 13 files changed, 28 insertions(+), 27 deletions(-) diff --git a/build/nogo_config.json b/build/nogo_config.json index f7d992f5d6ffb..9d3f91a965351 100644 --- a/build/nogo_config.json +++ b/build/nogo_config.json @@ -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", diff --git a/expression/aggregation/agg_to_pb.go b/expression/aggregation/agg_to_pb.go index 1d90ab02fb253..fa74965292e6f 100644 --- a/expression/aggregation/agg_to_pb.go +++ b/expression/aggregation/agg_to_pb.go @@ -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()) diff --git a/expression/aggregation/avg.go b/expression/aggregation/avg.go index a08aeb4f5cc50..7bc839ae3fb0f 100644 --- a/expression/aggregation/avg.go +++ b/expression/aggregation/avg.go @@ -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} } diff --git a/expression/aggregation/base_func.go b/expression/aggregation/base_func.go index 236761a2a4cc2..989ff1588aaca 100644 --- a/expression/aggregation/base_func.go +++ b/expression/aggregation/base_func.go @@ -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) @@ -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) @@ -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) @@ -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) } @@ -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) diff --git a/expression/aggregation/bit_and.go b/expression/aggregation/bit_and.go index fcb4aeb806874..4ba3645e3569f 100644 --- a/expression/aggregation/bit_and.go +++ b/expression/aggregation/bit_and.go @@ -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) } @@ -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 } diff --git a/expression/aggregation/bit_or.go b/expression/aggregation/bit_or.go index f5709a0575ca8..fe34d3ce03bfc 100644 --- a/expression/aggregation/bit_or.go +++ b/expression/aggregation/bit_or.go @@ -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) } @@ -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 } diff --git a/expression/aggregation/bit_xor.go b/expression/aggregation/bit_xor.go index e30210746d0d3..8ca72c3afc8f3 100644 --- a/expression/aggregation/bit_xor.go +++ b/expression/aggregation/bit_xor.go @@ -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) } @@ -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 } diff --git a/expression/aggregation/concat.go b/expression/aggregation/concat.go index 56d1feaced896..f59a151505feb 100644 --- a/expression/aggregation/concat.go +++ b/expression/aggregation/concat.go @@ -37,7 +37,7 @@ 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 { @@ -45,7 +45,7 @@ func (cf *concatFunction) writeValue(evalCtx *AggEvaluateContext, val types.Datu } } -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 { diff --git a/expression/aggregation/count.go b/expression/aggregation/count.go index a2c59dcbd361a..f867694735b65 100644 --- a/expression/aggregation/count.go +++ b/expression/aggregation/count.go @@ -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)) @@ -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 } diff --git a/expression/aggregation/descriptor.go b/expression/aggregation/descriptor.go index 3015b4718a226..892a97b44f6fb 100644 --- a/expression/aggregation/descriptor.go +++ b/expression/aggregation/descriptor.go @@ -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. diff --git a/expression/aggregation/first_row.go b/expression/aggregation/first_row.go index bcb06b5caa825..e299859560a77 100644 --- a/expression/aggregation/first_row.go +++ b/expression/aggregation/first_row.go @@ -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 } @@ -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 } diff --git a/expression/aggregation/max_min.go b/expression/aggregation/max_min.go index 10f312d275023..0fdb319faa23c 100644 --- a/expression/aggregation/max_min.go +++ b/expression/aggregation/max_min.go @@ -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 } diff --git a/expression/aggregation/sum.go b/expression/aggregation/sum.go index 9e0f6ab2a4c31..489c5ad2a18be 100644 --- a/expression/aggregation/sum.go +++ b/expression/aggregation/sum.go @@ -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 }