Skip to content

Commit

Permalink
* : replace fmt.Sprint with strconv (#31718)
Browse files Browse the repository at this point in the history
ref #31716
  • Loading branch information
hawkingrei authored Jan 17, 2022
1 parent 8bf4942 commit 465f655
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 32 deletions.
3 changes: 2 additions & 1 deletion br/pkg/lightning/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"sync/atomic"
"time"
Expand Down Expand Up @@ -422,7 +423,7 @@ func (s *tableRestoreSuiteBase) SetUpSuite(c *C) {
FileMeta: mydump.SourceFileMeta{
Path: fakeFileName,
Type: mydump.SourceTypeSQL,
SortKey: fmt.Sprintf("%d", i),
SortKey: strconv.Itoa(i),
FileSize: 37,
},
})
Expand Down
9 changes: 5 additions & 4 deletions br/pkg/logutil/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package logutil_test
import (
"context"
"fmt"
"strconv"
"strings"
"testing"
"time"
Expand All @@ -31,15 +32,15 @@ func assertTrimEqual(t *testing.T, f zapcore.Field, expect string) {

func newFile(j int) *backuppb.File {
return &backuppb.File{
Name: fmt.Sprint(j),
StartKey: []byte(fmt.Sprint(j)),
EndKey: []byte(fmt.Sprint(j + 1)),
Name: strconv.Itoa(j),
StartKey: []byte(strconv.Itoa(j)),
EndKey: []byte(strconv.Itoa(j + 1)),
TotalKvs: uint64(j),
TotalBytes: uint64(j),
StartVersion: uint64(j),
EndVersion: uint64(j + 1),
Crc64Xor: uint64(j),
Sha256: []byte(fmt.Sprint(j)),
Sha256: []byte(strconv.Itoa(j)),
Cf: "write",
Size_: uint64(j),
}
Expand Down
4 changes: 2 additions & 2 deletions br/pkg/pdutil/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"crypto/tls"
"encoding/hex"
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/pingcap/errors"
Expand All @@ -36,7 +36,7 @@ const (
func ResetTS(ctx context.Context, pdAddr string, ts uint64, tlsConf *tls.Config) error {
payload, err := json.Marshal(struct {
TSO string `json:"tso,omitempty"`
}{TSO: fmt.Sprintf("%d", ts)})
}{TSO: strconv.FormatUint(ts, 10)})
if err != nil {
return errors.Trace(err)
}
Expand Down
3 changes: 2 additions & 1 deletion br/tests/br_key_locked/locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"math/rand"
"net"
"net/http"
"strconv"
"time"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -343,7 +344,7 @@ func randStr() string {
length := rand.Intn(128)
res := ""
for i := 0; i < length; i++ {
res += fmt.Sprint(rand.Intn(10))
res += strconv.Itoa(rand.Intn(10))
}
return res
}
2 changes: 1 addition & 1 deletion cmd/importer/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func nextInt64Value(column *column, min int64, max int64) int64 {
}

func intToDecimalString(intValue int64, decimal int) string {
data := fmt.Sprintf("%d", intValue)
data := strconv.FormatInt(intValue, 10)

// add leading zero
if len(data) < decimal {
Expand Down
2 changes: 1 addition & 1 deletion dumpling/export/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func SelectTiDBRowID(db *sql.Conn, database, table string) (bool, error) {
_, err := db.ExecContext(context.Background(), tiDBRowIDQuery)
if err != nil {
errMsg := strings.ToLower(err.Error())
if strings.Contains(errMsg, fmt.Sprintf("%d", errBadFieldCode)) {
if strings.Contains(errMsg, strconv.Itoa(errBadFieldCode)) {
return false, nil
}
return false, errors.Annotatef(err, "sql: %s", tiDBRowIDQuery)
Expand Down
2 changes: 1 addition & 1 deletion executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (e *CancelDDLJobsExec) Next(ctx context.Context, req *chunk.Chunk) error {
}
numCurBatch := mathutil.Min(req.Capacity(), len(e.jobIDs)-e.cursor)
for i := e.cursor; i < e.cursor+numCurBatch; i++ {
req.AppendString(0, fmt.Sprintf("%d", e.jobIDs[i]))
req.AppendString(0, strconv.FormatInt(e.jobIDs[i], 10))
if e.errs[i] != nil {
req.AppendString(1, fmt.Sprintf("error: %v", e.errs[i]))
} else {
Expand Down
3 changes: 2 additions & 1 deletion expression/builtin_other_vec_generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion expression/generator/other_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ package expression
import (
"fmt"
"math/rand"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -329,7 +330,7 @@ func (g inGener) gen() interface{} {
}
return *j
case types.ETString:
return fmt.Sprint(randNum)
return strconv.FormatInt(randNum, 10)
}
return randNum
}
Expand Down
2 changes: 1 addition & 1 deletion expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5770,7 +5770,7 @@ func TestVitessHash(t *testing.T) {
"(1, 30375298039), " +
"(2, 1123), " +
"(3, 30573721600), " +
"(4, " + fmt.Sprintf("%d", uint64(math.MaxUint64)) + ")," +
"(4, " + strconv.FormatUint(uint64(math.MaxUint64), 10) + ")," +
"(5, 116)," +
"(6, null);")

Expand Down
2 changes: 1 addition & 1 deletion meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ func (m *Meta) GetBootstrapVersion() (int64, error) {

// FinishBootstrap finishes bootstrap.
func (m *Meta) FinishBootstrap(version int64) error {
err := m.txn.Set(mBootstrapKey, []byte(fmt.Sprintf("%d", version)))
err := m.txn.Set(mBootstrapKey, []byte(strconv.FormatInt(version, 10)))
return errors.Trace(err)
}

Expand Down
2 changes: 1 addition & 1 deletion planner/core/common_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ func getRuntimeInfo(ctx sessionctx.Context, p Plan, runtimeStatsColl *execdetail
}
copStats := runtimeStatsColl.GetCopStats(explainID)
analyzeInfo += copStats.String()
actRows = fmt.Sprint(copStats.GetActRows())
actRows = strconv.FormatInt(copStats.GetActRows(), 10)
}
memoryInfo = "N/A"
memTracker := ctx.GetSessionVars().StmtCtx.MemTracker.SearchTrackerWithoutLock(p.ID())
Expand Down
6 changes: 3 additions & 3 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ var defaultSysVars = []*SysVar{
if val, err := strconv.ParseUint(normalizedValue, 10, 64); err == nil {
if val > uint64(math.MaxUint32) {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(GroupConcatMaxLen, originalValue))
return fmt.Sprintf("%d", math.MaxUint32), nil
return strconv.FormatInt(int64(math.MaxUint32), 10), nil
}
}
}
Expand Down Expand Up @@ -501,7 +501,7 @@ var defaultSysVars = []*SysVar{
return nil
}},
{Scope: ScopeSession, Name: TiDBCurrentTS, Value: strconv.Itoa(DefCurretTS), ReadOnly: true, skipInit: true, GetSession: func(s *SessionVars) (string, error) {
return fmt.Sprintf("%d", s.TxnCtx.StartTS), nil
return strconv.FormatUint(s.TxnCtx.StartTS, 10), nil
}},
{Scope: ScopeSession, Name: TiDBLastTxnInfo, Value: strconv.Itoa(DefCurretTS), ReadOnly: true, skipInit: true, GetSession: func(s *SessionVars) (string, error) {
return s.LastTxnInfo, nil
Expand Down Expand Up @@ -888,7 +888,7 @@ var defaultSysVars = []*SysVar{
atomic.StoreUint64(&ExpensiveQueryTimeThreshold, uint64(tidbOptPositiveInt32(val, DefTiDBExpensiveQueryTimeThreshold)))
return nil
}, GetSession: func(s *SessionVars) (string, error) {
return fmt.Sprintf("%d", atomic.LoadUint64(&ExpensiveQueryTimeThreshold)), nil
return strconv.FormatUint(atomic.LoadUint64(&ExpensiveQueryTimeThreshold), 10), nil
}},
{Scope: ScopeSession, Name: TiDBMemoryUsageAlarmRatio, Value: strconv.FormatFloat(config.GetGlobalConfig().Performance.MemoryUsageAlarmRatio, 'f', -1, 64), Type: TypeFloat, MinValue: 0.0, MaxValue: 1.0, skipInit: true, SetSession: func(s *SessionVars, val string) error {
MemoryUsageAlarmRatio.Store(tidbOptFloat64(val, 0.8))
Expand Down
18 changes: 9 additions & 9 deletions sessionctx/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package variable

import (
"fmt"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -377,19 +376,20 @@ func (sv *SysVar) checkUInt64SystemVar(value string, vars *SessionVars) (string,
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MinValue), nil
return strconv.FormatInt(sv.MinValue, 10), nil
}
val, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return value, ErrWrongTypeForVar.GenWithStackByArgs(sv.Name)
}
if val < uint64(sv.MinValue) {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MinValue), nil
return strconv.FormatInt(sv.MinValue, 10), nil
}
if val > sv.MaxValue {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MaxValue), nil
return strconv.FormatUint(sv.MaxValue, 10), nil

}
return value, nil
}
Expand All @@ -404,11 +404,11 @@ func (sv *SysVar) checkInt64SystemVar(value string, vars *SessionVars) (string,
}
if val < sv.MinValue {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MinValue), nil
return strconv.FormatInt(sv.MinValue, 10), nil
}
if val > int64(sv.MaxValue) {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MaxValue), nil
return strconv.FormatUint(sv.MaxValue, 10), nil
}
return value, nil
}
Expand All @@ -418,7 +418,7 @@ func (sv *SysVar) checkEnumSystemVar(value string, vars *SessionVars) (string, e
// This allows for the behavior 0 = OFF, 1 = ON, 2 = DEMAND etc.
var iStr string
for i, v := range sv.PossibleValues {
iStr = fmt.Sprintf("%d", i)
iStr = strconv.Itoa(i)
if strings.EqualFold(value, v) || strings.EqualFold(value, iStr) {
return v, nil
}
Expand All @@ -436,11 +436,11 @@ func (sv *SysVar) checkFloatSystemVar(value string, vars *SessionVars) (string,
}
if val < float64(sv.MinValue) {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MinValue), nil
return strconv.FormatInt(sv.MinValue, 10), nil
}
if val > float64(sv.MaxValue) {
vars.StmtCtx.AppendWarning(ErrTruncatedWrongValue.GenWithStackByArgs(sv.Name, value))
return fmt.Sprintf("%d", sv.MaxValue), nil
return strconv.FormatUint(sv.MaxValue, 10), nil
}
return value, nil
}
Expand Down
4 changes: 2 additions & 2 deletions statistics/handle/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package handle

import (
"context"
"fmt"
"strconv"

"github.com/cznic/mathutil"
"github.com/pingcap/errors"
Expand Down Expand Up @@ -428,5 +428,5 @@ func getFullTableName(is infoschema.InfoSchema, tblInfo *model.TableInfo) string
}
}
}
return fmt.Sprintf("%d", tblInfo.ID)
return strconv.FormatInt(tblInfo.ID, 10)
}
3 changes: 2 additions & 1 deletion store/driver/txn/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -53,7 +54,7 @@ func extractKeyExistsErrFromHandle(key kv.Key, value []byte, tblInfo *model.Tabl
if handle.IsInt() {
if pkInfo := tblInfo.GetPkColInfo(); pkInfo != nil {
if mysql.HasUnsignedFlag(pkInfo.Flag) {
handleStr := fmt.Sprintf("%d", uint64(handle.IntValue()))
handleStr := strconv.FormatUint(uint64(handle.IntValue()), 10)
return genKeyExistsError(name, handleStr, nil)
}
}
Expand Down
2 changes: 1 addition & 1 deletion table/tables/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ func (t *partitionedTable) locateRangeColumnPartition(ctx sessionctx.Context, pi
if err == nil {
val, _, err := e.EvalInt(ctx, chunk.MutRowFromDatums(r).ToRow())
if err == nil {
valueMsg = fmt.Sprintf("%d", val)
valueMsg = strconv.FormatInt(val, 10)
}
}
} else {
Expand Down

0 comments on commit 465f655

Please sign in to comment.